Тёмный
No video :(

Does it matter how I write my infinite loops? (for vs. while?) 

Jacob Sorber
Подписаться 163 тыс.
Просмотров 10 тыс.
50% 1

Опубликовано:

 

27 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 161   
@JacobSorber
@JacobSorber 3 года назад
So, what are your theories?
@AtomToast
@AtomToast 3 года назад
In the end it's just personal preference but in the idea that code should be readable and maintainable first, while(true) is just a lot saner. Also since this is something you can write in pretty much any language (that has while loops) it's more universal
@gregforgotmylastname2905
@gregforgotmylastname2905 3 года назад
I use while loop all the time. It's just something I've always been doing since I started coding two years ago. Not very sure why though, maybe because it looks simpler.
@zrodger2296
@zrodger2296 3 года назад
I prefer while. As someone pointed out, for loops are usually associated with a loop index. In fact, my personal header file has a macro FOREVER that just evaluates to a while (true).
@badwolf8112
@badwolf8112 3 года назад
alternative title: "do you need to switch to a new compiler?" (my theory is: there shouldn't be a difference in the assembly)
@badwolf8112
@badwolf8112 3 года назад
2nd theory: yes, it matters, stop rewriting loops, just use map/reduce/filter. it takes a lil while to get used to it, but it literally means you don't ever have to manually write loops again. not sure how much of an improvement it is in C, tho, because the amount of support for functional style might not be enough for this to be practical
@noodlish
@noodlish 3 года назад
Clearly goto is the best option
@Nick-lx4fo
@Nick-lx4fo 3 года назад
asm ("jmp $"); is clearly the superior way
@civilizedgangster8024
@civilizedgangster8024 3 года назад
@@Nick-lx4fo pfffsh you guys write it like that? I write 001110110101101100, amateurs
@casperes0912
@casperes0912 3 года назад
@@civilizedgangster8024 Unless you actually looked up that that's the binary opcode for a jump instruction, I'm disappointed. - Which it isn't cause I just noticed that that's 18 bits wide
@casperes0912
@casperes0912 3 года назад
@@Nick-lx4fo You beat me to that one :P
@civilizedgangster8024
@civilizedgangster8024 2 года назад
@@casperes0912 yes, but it was intended as a joke...not to be taken seriously you know...
@Riciadavinci
@Riciadavinci 3 года назад
A video on Infinite Loops? I have been waiting FOR a WHILE! :P
@JacobSorber
@JacobSorber 3 года назад
Thanks. I needed that this morning.
@potatoxel7800
@potatoxel7800 3 года назад
and i have been waiting FOR(;;)
@thedoublehelix5661
@thedoublehelix5661 3 года назад
I had no idea about the for version of infinite loops lol. I think that while(true) is better because for loops are typically used for looping with an index and while loops are the unstructured alternative so it makes sense to do something as crazy as an infinite loop with while.
@SimonJentzschX7
@SimonJentzschX7 3 года назад
how about #define ever ;; for (ever) { } But I agree, it does not really matter, but since most of my infinite loops also contain actions to execute afterwards, I prefer the for-style: for (;;sleep(1)) { }
@TheCocoaDaddy
@TheCocoaDaddy 3 года назад
I used to use the "#define EVER" 'trick' for fun. lol
@lionkor98
@lionkor98 3 года назад
#define forever for(;;)
@maxaafbackname5562
@maxaafbackname5562 2 года назад
#define ever (;;) for ever { }
@edgarbonet1
@edgarbonet1 2 года назад
I use that #define in my head: I write “for (;;)” and read it “forever”. That's why I find the for loop more intuitive: one would never say “while true” in everyday language, whereas “forever” is quite common.
@edgeeffect
@edgeeffect Год назад
I hate the preprocessor.... but that is PURE ART!
@JonitoFischer
@JonitoFischer 3 года назад
#define scratching_balls true while (scratching_balls) { // do nothing }
@jacobschmidt
@jacobschmidt 3 года назад
In the olden days, compilers weren't complex enough to make even simple optimizations. This is why, for example, the increment operator exists. All modern compilers treat "i += 1" and "++i" the same way, but for old compilers a different syntax was necessary to make the optimization. Now, as for the battle between for (;;) {} and while (true) {} - in the olden days the former would have spit out exactly what you intended, a straight loop with no comparison, while the latter would have rather dumbly checked to see if 1 doesnt equal zero every time. Because of this difference, it became standard for people to use for (;;) {}. However, for (;;) {} is (arguably) less readable than while (true) {}, so for people with modern compilers, where it spits out the exact same assembly, it has become more and more common to use the while form. Yet the old standard still persists, and perhaps, rightly so (or perhaps not, who cares?).
@OGBhyve
@OGBhyve 3 года назад
Jacob Schmidt This is some interesting insight. Do you think this could be reproduced with say gcc 3.X?
@jacobschmidt
@jacobschmidt 3 года назад
@@OGBhyve gcc 4.1.2 with -O0 optimizes the comparison away. It is probably one of the easiest optimizations to make, (and was thus probably one of the first things to be optimized away) but it is *an optimization*, which is the point. At the time the language was designed, such optimizations were not used, and the code you typed was much more intimately connected with the assembly.
@jacobschmidt
@jacobschmidt 3 года назад
@@OGBhyve just checked ppci with -O2, and it did not optimize
@lawrencemanning
@lawrencemanning 3 года назад
I always thought/assumed a++; was a shorthand not a way to tell the compiler to insert an increment instruction. Are you sure about this?
@OGBhyve
@OGBhyve 3 года назад
@@jacobschmidt Not familiar with that one. Just tested on GCC 2.96. The assembly generated for both was the same using the jmp instruction and there wasn't a cmp instruction to be found. Interestingly, MSVC 19.27 does do a comparison for the while loop when using /O0. Once you use /O1 or higher though, it is optimized away.
@ack_
@ack_ 3 года назад
I believe writing clear, understandable code is the main and common goal of programmers, instead of arguing about minor details and syntactic preferences, where the debate itself brings more anger and confusion than the actual "issue". Anyways, while(true) looks a lot better to me and I'm sticking with that.
@alvinbee6194
@alvinbee6194 3 года назад
I agree most of the time but that's not always true. On embedded systems for example you have the option to code for speed or size which is a trade off. The word hacker comes from this; hackers program something brilliant often difficult to understand but if you take time to understand it you'll learn a deeper understanding of programming.
@Diego-my9gc
@Diego-my9gc 3 года назад
@@alvinbee6194 I agree with this, programming is a very extensive area and you have to see it objectively in order to understand why things are. Today's "Coders" seem to think that everything revolves around what they do, much of this is because today these guys are programmers based on watching online courses and do not have the proper academic training. They program with a mindset that resources are limitless. But those of us who have experience developing embedded software work with very limited resources, both in capacity and speed, and we try to program while maintaining the readability of the code but with a greater focus on optimization.
@dealloc
@dealloc 3 года назад
@@alvinbee6194 Right, but embedded systems usually have guidelines, or rather rules for specific cases where it does make a difference; in which case you'd probably be best off by making the compiler do the grunt work, so that you can keep a readable source code without strange "hacks". An example of this is in any transportation system, train, aviation, etc. They have explicit guidelines and standards for how to write code certain ways, and avoid certain patterns, but they also have compilers that does away with most of the headaches, so you can focus on writing code and not sweat of the details. It's not always possible, though, but in a lot of cases it is.
@oj0024
@oj0024 3 года назад
Here are some other options: - while (1) - what about do while? - labels - who needs loops anyway, recursion all the way Also an extra argument for for(;;), if you popularize this style more people will be aware, that you can omit expressions from for loops.
@JacobSorber
@JacobSorber 3 года назад
True. It does force people into a better understanding of what a for loop actually is.
@SoulSukkur
@SoulSukkur 3 года назад
I don't think recursion is a valid alternative. How would you avoid running out of room in the runtime stack?
@Sahilbc-wj8qk
@Sahilbc-wj8qk 3 года назад
Well recursion is not optimum when it's come to large software where lot of code is running and allocating stack space. So it's important. Depending on context.
@Sahilbc-wj8qk
@Sahilbc-wj8qk 3 года назад
@@SoulSukkur .
@kaminutter
@kaminutter 3 года назад
Use Goto statement for recursion, as there shouldn't be any addition to the stack :D
@shadyganem5448
@shadyganem5448 3 года назад
There are much more important stuff to focus on. such as, where to put the frame braces '{'. I think they should be on a new line
@sayanghosh6996
@sayanghosh6996 3 года назад
nooooooooo at the end of the current line
@shadyganem5448
@shadyganem5448 3 года назад
@@sayanghosh6996 your kind represent the evil in this world. Why do you hate symmetry. (I am joking of course)
@wendolinmendoza517
@wendolinmendoza517 Год назад
Jacob disagrees 5:32 and so do I
@rdwells
@rdwells 2 года назад
Well said, as usual. One addition to your advice at the end: while shaking your head listening to arguments to this, add an eye roll. FWIW, I favor while(true), mainly because it was never obvious to me why the blank conditional expression in for(;;) should evaluate to true (other than that the standard says so).
@gimpzilla
@gimpzilla 3 месяца назад
My understanding is For Loops calculate the incremental after the statements, whereas While Loops can manipulate the increment before running statements
@yogxoth1959
@yogxoth1959 3 года назад
I would never use the “for”-version, but one argument I can come up with in favor of it would be that it’s faster to type.
@dealloc
@dealloc 3 года назад
Use whatever makes sense based on the context. A good rule of thumb is to use while loops for truthy or falsy statements, like while (running), while (cursor > 1), while (!empty(array)) etc. think of it as what you'd put in an if/else condition. For loops are great for cases where you iterate over something specific, or need to keep track of indicies, as it glues the initialization, condition and update expressions together, rather than splitting them up: for (init; condition; update). While you can omit one or more expressions in the for loop, but it can be easy to miss when reading the code. At that point, a while loop may be more readable.
@n0ame1u1
@n0ame1u1 2 года назад
In theory, on some older or non-optimized compilers, while(true) might be slower than for(;;). But there really should be no case where for(;;) is slower than while(true).
@EidosGaming
@EidosGaming 3 года назад
This is so irrelevant but still I'm definitely converting to for(;;) so that I can mock people using while(true) for being noobs
@cole-nyc
@cole-nyc 3 года назад
You should check out compiler explorer, it's perfect for videos like that :)
@JacobSorber
@JacobSorber 3 года назад
Agreed. It's a great comparison tool.
@SadgeZoomer
@SadgeZoomer 3 года назад
Your channel is a gem Jacob, it really is
@JacobSorber
@JacobSorber 3 года назад
Thanks, David.
@truberthefighter9256
@truberthefighter9256 2 года назад
Never seen that for version. i do not wanna use it or necessarily see it, because it makes me think of some depressed writing in the internet. Just having such a friend is enough
@bbq1423
@bbq1423 3 года назад
Why not just: loop: //do something goto loop;
@TomStorey96
@TomStorey96 2 года назад
Run it through compiler explorer and see for yourself. 😉 It'll either spit out the exact same assembly as the other two forms, or it's not going to be very far off it.
@AWriterWandering
@AWriterWandering 3 года назад
One of the things people either love or hate about the Go language is that it doesn’t even give you a choice. There are only For loops!
@Awesomegeorge301
@Awesomegeorge301 3 года назад
A point against while(true) is that it requires the user to #include and may not compile if a new user doesn't include it
@timwmillard
@timwmillard 3 года назад
while(1) will solve that problem. I guess you could argue it’s not as readable though.
@arielspalter7425
@arielspalter7425 3 года назад
It is the convention in all programming languages. That in itself is the sole reason for me to choose while (true). I always try to stay away from language specific practices (if there is no reason for it of course). That's why I hate modern c++ with all the unique and unintuitive semantics that you see no where else.
@SimGunther
@SimGunther 3 года назад
Adding fuel to the fire, while/do-while are bloat that are "necessary" to abstract the anti-pattern of looping without initial variable setup for readability/comprehension's sake. Whichever infinite loop style you choose, be consistent and don't shove it down people's throat.
@dealloc
@dealloc 3 года назад
do while is different from while in that a do expression will _always_ run at least once, whether the initial condition was falsy or not. This can be useful for cases where the code needs to do something before the loop condition can be evaluated. That's not to say that you should use do/while for every case where it makes sense; e.g. if you don't want side-effects and require variables to be initialized upfront, by all means don't use do.
@hamed9327
@hamed9327 2 года назад
compilers are super smart!
@KarlKatten
@KarlKatten 3 года назад
personally i prefer while(1337) /s :'D
@SongsFromMyHead
@SongsFromMyHead 2 года назад
Speaking to the concern of TRUE being redefined and breaking 'while(TRUE)', use 'while(1)'. If '1' ever gets redefined, you've got much bigger problems! 🙂
@DrOggy67
@DrOggy67 3 года назад
When using "while (true)", that "true" must be defined somewhere. So maybe "while(1>0)" is a better choice. But because of the condition in both cases, I would prefer "for(;;)", because it makes clear, that there is really no condition that must be checked. It is therefore a real for-ever loop.
@skaruts
@skaruts 3 года назад
or just "while(1)"
@sukhbirsingh8053
@sukhbirsingh8053 Год назад
Some people were fighting on while(2), while(37), while(0 == 0)
@dbrunecz78
@dbrunecz78 3 года назад
i like for(;;) for mostly the same reasons why while(true) was left out of other languages, it's redundant and having more than one way to do something leads to non-useful variations. Also, one way to interpret the mentioned danger of 'meaning'(or the definition) changing that's more realistic is just that some day you may need to re-factor that while (true) code to actually be conditional or non-infinite, at which point it'll likely be most natural to switch over to for anyway. when maintaining large code-bases for a period of time you come to value uniformity(assuming it's not artificial or has other side-effects/costs). that's the primary reason the linux kernel leans towards using for (;;) any decent compiler should produce identical code, after that you're just catering to beginner programmers. Another way of stating that is you're lowering the bar on what you expect developers/contributors to be comfortable with, and lowering the bar just eases things short term at the expense of long term maintainability. also if you get in the habit of using for (;;) since it's effectively a superset of the functionality of while(true) and can always be used whenever either is an option, you will never waste time internally debating which to use/which is better also, another minor ease of use thing is just during debugging, it's a bit quicker/easier to modify the for loop to do useful things to help locate issues(add a loop counter, etc.)
@dealloc
@dealloc 3 года назад
> was left out of other languages, it's redundant and having more than one way to do something leads to non-useful variations That depends on how you wan't to read the code. In Rust, there are four types of loop expressions: for (iterator), while (predicates), while let (patterns) and loop (infinite). Each have their own meaning, whereas in C and C++ it's not as rigorous and can lead to confusion and bugs (you can test conditions with for and while loops, both can be made infinite, etc.) > some day you may need to re-factor that while (true) code to actually be conditional or non-infinite, at which point it'll likely be most natural to switch over to for anyway. That highly depends what your loop does. If your loops is meant to run until a predicate is false, a while loop is more readable than a for. For loops are great for iteration, rather than conditional looping. > when maintaining large code-bases for a period of time you come to value uniformit It's better to value readability and intent with context. While you _could_ exclusively use for loops for everything, using it for simple conditions (e.g. for (;condition;)) is less readable and more error-prone than while loops (e.g. while (condition)) with explicit initialization. > it's a bit quicker/easier to modify the for loop to do useful things to help locate issues That depends on what you're debugging, of course. I'd argue that it's much safer to explicitly define your debugging statements/variables outside so that they are easier to notice so you don't ship them in production code.
@Diego-my9gc
@Diego-my9gc 3 года назад
I Use the "for" just because using "while" the compiler that aI use gives a warning "condition allways true"
@dealloc
@dealloc 3 года назад
This warning only shows up in Visual C++ compiler afaik. However, this is actually a good argument against using for(;;), since the compiler helps you avoid infinite loops-which are usually a code smell or a bug, since you'll have to make sure your break out of the loop at some point to stop the execution inside the program. Examples of this is something like while(i >= 0) { --i }; which will be infinite if `i` is unsigned, or with macros: while(MACRO(i)) which will be infinite if the macro expands to a truthy value.
@blueguy5588
@blueguy5588 2 года назад
In the same way that you should try to limit the use of else in if-statements, you should always look for the positive (i.e. while) and avoid trying to catch the contrapositive. I actually prefer for-loops, especially for hitting items in a data structure, but while makes more sense in a lot of cases.
@lionkor98
@lionkor98 3 года назад
for(;;) is my preferred way because it shows that its a deliberate decision, not a "lets do this while(true) and change the condition later". It shows intent and that's important. It also reads nicely, like "for (ever)". instead of "while true". "do {} while (true)" is just wrong in my opinion. Generally, only use do-while if you need to, not by default.
@tommasobonvicini7114
@tommasobonvicini7114 3 года назад
The fastest way to generate assembly code for simple snippets of code like these is godbolt.org You can also use many different combinations of compilers and architectures, which is perfect for speculating about past and present performance of a piece of code.
@paherbst524
@paherbst524 2 года назад
I always use "while". It's more universal. "for" seems superfluous.
@bob_kazamakis
@bob_kazamakis 3 года назад
I just write programs such that when I call exec to itself it acts like a for/while
@JacobSorber
@JacobSorber 3 года назад
I love this one. Thank you for being a part of this.
@tko9753
@tko9753 3 года назад
I’ll just be in the safe side and use for loops although that I don’t believe that while loops are prone to error, and for readability I can just caption to explain that it’s a infinite loop
@alvinbee6194
@alvinbee6194 3 года назад
Awesome you hit it right on the head. You have to consider the architecture, the compiler and it's optimization. In older compilers it does matter and for some architecture it does matter. How do you tell by inspecting the assembly code or machine code ISA.
@jarvenpaajani8105
@jarvenpaajani8105 3 года назад
You can use for(;;) if you don't want to include standard header files, True would be undefined. Usual on embedded code.
@skaruts
@skaruts 3 года назад
or while(1)
@n0ame1u1
@n0ame1u1 Год назад
@@skaruts while(2) to be more chaotic
@honestlynuts__
@honestlynuts__ 3 года назад
I think the while true way to do it is much more readable to because it is not ambiguous, It says what is does. It loops while the value of true is equal to true. but for ;; is less readable in that what does the ';;' mean. I personally had a lot of trouble finding out it's meaning when I started. But it's just what you prefer. I personally want my code to be more readable and be understood by beginners whom don't know what ';;' means. But do what you like, I don't care what way you implement your infinite loops, as long it works and is well formatted.
@dgholstein
@dgholstein Год назад
I'd love to hear its implications with interrupt driven programming, especially with C instead of C++. I worry that it may be using system resources, or switching to the process, when an infinite loop is used.
@hatkidchan_
@hatkidchan_ 3 года назад
I use infinite for loops sometimes (`for (int i = 0; ; i++)`) when I need counter, like in example code you provided, but for other situations when I don't need to change anything I prefer `while` loop because it's known pattern and you can just look at it and say "hm, yes, it's infinite loop"
@Spiderboydk
@Spiderboydk 2 года назад
Better use unsigned int instead, because int is not allowed to overflow.
@nunyobiznez875
@nunyobiznez875 3 года назад
I like to use forever loops, because the intent is clear, but also because it amuses me, and I need any amusements I can get while writing code- #define EVER ;; for(EVER)
@JannisAdmek
@JannisAdmek 3 года назад
Hey Jacob, you should use tabs instead of spaces... just kidding! I prefere while(1) but it really doen't matter for me. Rust even made a specially loop to get round this issue, called loop {}
@nicholasbonjour6532
@nicholasbonjour6532 3 года назад
If it's only an infinite loop, I say while(true) for readability. But just to add some points to the for loop case, if there is some regular action you're performing at the end of every loop, the indefinite for-loop looks a lot more appealing and can usually make your code shorter (and perhaps remove the need for curly braces).
@wendolinmendoza517
@wendolinmendoza517 Год назад
5:32
@rustycherkas8229
@rustycherkas8229 2 года назад
'while()' should only be present in code with its partner 'do' ( "do blah while(condition);" ) If you want to test a condition at the top of a loop, ALWAYS use 'for'. What could be clearer than: for( ;true; ) ??!! jk... gotta love these senseless "holy wars"... A presentation focussing on mastering "flow control" might be useful... One usually wants to exit an infinite loop at some time. Beginners (we all were at one time) can write incomprehensible code with numerous state flags (or arbitrary conditions) being evaluated to break/continue processing... One of my favourites has been a state machine with an enum naming discrete states and a for loop containing a switch (or two)... The last thing before the 'break' at the end of each 'case' is to set the state for the next iteration. This eliminates infinite loops because some processing somewhere will set the new state to 'eDone' that is tested by the bounding for() or while()...
@DarshanSenTheComposer
@DarshanSenTheComposer 3 года назад
if u wanna assert dominance, go for the for loop, otherwise go for the while loop
@ErikBongers
@ErikBongers 3 года назад
Ok, but what about toilet paper orientation? Hang in front? Or hang behind?
@JacobSorber
@JacobSorber 3 года назад
Not sure I want to go there. Just too contentious. 😀
@alfredkonneh2963
@alfredkonneh2963 Год назад
I have crashed my computer more them 30 times since I started learning loops. I haven't gotten the logic yet how to avoid it
@MrAliemre03
@MrAliemre03 3 года назад
how about do{ for(;;) } while(true)
@wChris_
@wChris_ 3 года назад
do you know godbolt.org? i assume not. its basicly a compiler explorer to view the assembly
@JacobSorber
@JacobSorber 3 года назад
I am familiar with it, thanks to other helpful people like you. Thanks. It's a cool tool.
@samuelgunter
@samuelgunter Год назад
just use Rust, which uses this syntax loop { // code }
@skaruts
@skaruts 3 года назад
Personally i just use while true because it's easier to type and read. I work on my own, so if something redefines "true" then I'll know my sanity needs to be checked. I mostly don't use C though, so I'm good. I'll never know the state of my sanity. :)
@lorenzo42p
@lorenzo42p 3 года назад
what if I make an infinite loop by recursively calling the main() function from within itself, but at the start of the function somehow modify the stack to clean up the repeating call, keeping the backtrace the same length
@WolvericCatkin
@WolvericCatkin 2 года назад
Rust: "Hey, what are you guys talking about...?"
@JohnHollowell
@JohnHollowell 3 года назад
I'm not quite sure I got that last thing down. Can I get a step-by-step tutorial video for the head shake?
@JacobSorber
@JacobSorber 3 года назад
Sure thing. Coming right up.
@gokulrajaking
@gokulrajaking 3 года назад
Please recommend some free static analysis tool and unit testing tool for embedded pure c
@shekharmaela2308
@shekharmaela2308 3 года назад
The only acceptable answer is the while loop.
@clarkd1955
@clarkd1955 3 года назад
Don't put infinite loops in your code. Make it a "for" loop with a scope that exceeds what you know is reasonable. Or you could put in a " and --limit" which will do the same thing for a while loop. Better yet, use data structures that have a well designed "next function" so your loop looks like "while (next(...)){" and let the system make sure you don't get a runaway loop. I program almost exclusively in C for the past 20 years (over 500,000 lines in many projects) and I have no infinite loops.
@JacobSorber
@JacobSorber 3 года назад
Thanks for the perspective. A lot of infinite loops can and should be replaced with not-so-infinite alternatives. That said, I'm guessing you don't do a lot of embedded systems programming, where many device main loops are intended to run for(;;). 😉
@finnaerix9837
@finnaerix9837 3 года назад
What about goto. Shouldn't it be the fastest, because it doesn't need to check any values every time it loops.
@ashwinnat666
@ashwinnat666 3 года назад
I guess it would be the same. If you look at the assembly output in the video, the jmp instruction is used, which doesn't check for any conditions before jumping. My guess is that the goto version of the code will also look the same
@JacobSorber
@JacobSorber 3 года назад
That's my guess, too.
@ctobi707
@ctobi707 3 года назад
I love this channel
@lawrencemanning
@lawrencemanning 3 года назад
I quite like: #define FOREVER for (;;)
@mow3890
@mow3890 3 года назад
In my experience hardcode Embedded engineer use while (1) while not embedded folks use for(;;) loop,
@RandomDays906
@RandomDays906 3 года назад
while(1==1) { // do something }
@marusdod3685
@marusdod3685 3 года назад
i think one is just a macro wrapping the other
@thomasipad7719
@thomasipad7719 3 года назад
😂😂😂 Great!! Thanks! I always preferred while already...
@bastawa4569
@bastawa4569 3 года назад
One is 1 character shorter. There are coding challenge sites where you might want to code golf in C:)
@Uerdue
@Uerdue 2 года назад
Well, in that case goto should be even shorter. (Unless you have so many infinite loops that you run out of possible 1-character labels of course.)
@KangJangkrik
@KangJangkrik 3 года назад
This is how I write infinite loop: void loop() { // }
@zakarouf
@zakarouf 3 года назад
#define true random()&1 #define false true^1 while(true){ //Works 50% of the time :D }
@gokulrajaking
@gokulrajaking 3 года назад
100% undefined because no seed to random function
@lionkor98
@lionkor98 3 года назад
@@gokulrajaking That's not true, if rand() is used before any calls to srand(), rand() behaves as if it was seeded with srand(1).
@gokulrajaking
@gokulrajaking 3 года назад
@@lionkor98 seed same means, alway random number sequence will same
@crusaderanimation6967
@crusaderanimation6967 3 года назад
True legends Legends use goto
@sayanghosh6996
@sayanghosh6996 3 года назад
for is shorter tho 🤷‍♂️🤷‍♂️🤷‍♂️🤷‍♂️
@stevenfrawley4826
@stevenfrawley4826 3 года назад
When discussing software or firmware design, we have always referred to an infinite loop as a 'while-one-loop'. I have never heard anyone speak of a 'for-with-no-entries' block...
@abdallahben0
@abdallahben0 3 года назад
this is the best use practice specially if you have to check code coverage :) : const boolean bState= true; while(bState) { ..... }
@wendolinmendoza517
@wendolinmendoza517 Год назад
Am I going to be the next president of the universe? 5:32 Do you, Jacob, love me? 5:32 Will Elon Musk ever give up w33d? 5:32 Do you think this is funny? 5:32
@mback3713
@mback3713 Год назад
#define forever_loop for(;;)
@Spiderboydk
@Spiderboydk 2 года назад
It's just bikeshedding.
@moccaloto
@moccaloto 3 года назад
I bet that people who use for loops also turn the toilet paper roll the wrong way round 🤪 but other than that I truly don't care what people use as long as they are consistent
@benjaminshinar9509
@benjaminshinar9509 3 года назад
*looks sadly* *shakes* tsk, tsk, tsk, personally, I prefer the while(true) version. for(;;) looks incomplete and semi-colons call attention to themselves.
@ritiksahu1844
@ritiksahu1844 3 года назад
Does my comment lead you to make this if so I am happy. I helped you
@edgeeffect
@edgeeffect Год назад
I like to troll my colleagues by using goto. ;) I Pascal I would define a false boolean constant HellFreezesOver and then use repeat .... until HellFreezesOver.
@phildem414
@phildem414 Год назад
What about do{...} while(true); 🤔🤡
Далее
How to Check Your Pointers at Runtime
14:12
Просмотров 31 тыс.
How does fork work with open files?
13:12
Просмотров 9 тыс.
Ajdarlar...😅 QVZ 2024
00:39
Просмотров 454 тыс.
The Most Legendary Programmers Of All Time
11:49
Просмотров 552 тыс.
Just In Time (JIT) Compilers - Computerphile
10:41
Просмотров 269 тыс.
The Inline Keyword in C.
16:18
Просмотров 57 тыс.
How do I access a single bit?
11:07
Просмотров 20 тыс.
Another way to check pointers at runtime in C
12:16
Просмотров 12 тыс.
Should you learn C++?? | Prime Reacts
20:29
Просмотров 352 тыс.
How I Would Learn To Code (If I Could Start Over)
13:43