Infinite loop in C++
-
Infinite loop in C++
-
Infinite loop in C++
I use them both, but I try not to mix them.
I think that "for (;;)" looks cooler but it doesn't read as well as "while(1)" or "while(true)"
To understand why "while(true)" works, you only have to know the "while" syntax. I think even if you know the "for" syntax, it's not obvious that it will even compile without {stuff}, and it's also not obvious that an empty test condition will evaluate "true".
As for do..while, I just don't like reading a code block before I know the loop conditions.
-
I use them both, but I try not to mix them.
I think that "for (;;)" looks cooler but it doesn't read as well as "while(1)" or "while(true)"
To understand why "while(true)" works, you only have to know the "while" syntax. I think even if you know the "for" syntax, it's not obvious that it will even compile without {stuff}, and it's also not obvious that an empty test condition will evaluate "true".
As for do..while, I just don't like reading a code block before I know the loop conditions.
...and goto is fine, but I just think you have to be careful with it.
-
undefined oblomov@sociale.network shared this topic
-
Infinite loop in C++
-
I use them both, but I try not to mix them.
I think that "for (;;)" looks cooler but it doesn't read as well as "while(1)" or "while(true)"
To understand why "while(true)" works, you only have to know the "while" syntax. I think even if you know the "for" syntax, it's not obvious that it will even compile without {stuff}, and it's also not obvious that an empty test condition will evaluate "true".
As for do..while, I just don't like reading a code block before I know the loop conditions.
@North very much agreed; I do accept do {} while (0) as a way to manage small “easy way out” block. Yes, it can be replaced with a goto.
-