Sometimes when im reading code it appears to be written for with no params to load
Like this:
for(;;)
{
/*Some piece of code*/
}
Sometimes when im reading code it appears to be written for with no params to load
Like this:
for(;;)
{
/*Some piece of code*/
}
Any combination of the three expressions can omitted, including all of them.
If the first or third expression is omitted, no code is evaluated when those expression would be evaluated. (If both of these are omitted, one effectively has a pure while
loop.)
If the middle expression is omitted, it's as if a true expression was provided. This creates a loop that can only be exited using break
, return
, exit
and long jumps.
For example, the following loops until a valid answer is given.
int x;
for (;;) { // Or `while (1)`
display_prompt();
x = get_answer();
if (is_valid(x))
break;
printf("Invalid input\n");
}
The for
loop has three parts: initialization, test, and update.
Any of these can be omitted. By having none of them included, you've created an infinite loop and need to include some kind of test with break
inside the body of the loop.
For the same effect, one can use a while
loop:
while (1) {
}