How does for (?;) work?

5

It's probably duplicated, but I did not find it here in SOpt, and I do not know how to search on Google.

How does the for loop work in this syntax?

for(;;)
{
//...
}
    
asked by anonymous 20.10.2017 / 18:29

1 answer

10

In this specific form is an loop infinity. It will only stop when you have break .

The structure of a for loop in most mainstream languages is as follows:

for(inicializacao; condicao; pós loop)

Where:

  • inicializacao : is a statement run only once - before the first loop. It's like a " pre-for ";

  • condicao is a statement run before each loop and it will define whether the next loop will be executed or not. It's like the "stop condition" of the repetitions, as soon as this statement returns% with the reps ending.

Any of these options can be omitted, ie empty statements . In this case, statement will do exactly what you want: nothing .

    
20.10.2017 / 18:30