What does such a design mean?
for(;;) { //операторы }
It is clear that the for
loop, but what about its parameters?
This is an infinite loop (equivalent to while(true) {}
). Sometimes this is needed. Exit from it is usually by break
, or by return
.
while (255){...}
will behave the same way :-) - gecubebut what about its parameters?
they are trivially omitted, therefore nothing happens at the beginning of the cycle, there are no checks for the end of the cycle, and there is no block describing the action, hence the cycle will work equivalently to the construction
while(true){...}
I also add that in the for loop and the body is optional. Therefore, there is also a reverse situation: the parameters are there, but the bodies are not. Because all the necessary operations are already in the parameters.
You will be surprised even more, but sometimes even such a construction makes sense:
do { make_me_happy(); } while(0)
Source: https://ru.stackoverflow.com/questions/127472/
All Articles
for (A; B; C) {D;}
<=>A; while (B) {D;C;}
A; while (B) {D;C;}
. Any of the elements can be skipped. If we skip B, then we take it as true. Well, we can always write not a block{...}
, but c;
:while (1); // вечный цикл
while (1); // вечный цикл
- gecube 2:07 pmfor (A; B; C, D)
- Specterfor (A1, A2; B; C1, C2)
. - gecube