How does the for(;;)work?

Asked

Viewed 1,089 times

5

It’s probably duplicated, but I didn’t find it here on Sopt, and I don’t know how to Google.

How the loop works for in that syntax?

for(;;)
{
//...
}
  • In what language?

  • It’s the same thing while(true) { }

  • The question itself already answers: https://answall.com/q/90180/101

  • 2

    Infinite loop. Initializes nothing, has no stop condition, has no incremental step

  • 1

    @Downvoter because the negative vote?

1 answer

11


In this specific form is a loop infinite. It will stop only when you have a break.

The structure of a loop for, in most languages mainstream is the following:

for(inicializacao; condicao; pós loop)

Where:

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

  • condicao is a statement executed before each loop and that will define whether the next loop will be executed or not. It is like the "stop condition" of the repeats, from the moment this statement return false the repetitions end.

  • pós loop is a statement that is executed after each loop.

Any of these options may be omitted, i.e., they may be statements empty. In this case, the statement will do exactly what you want: nothingness.

  • Thank you. Succinct and efficient answer, exactly what I wanted

Browser other questions tagged

You are not signed in. Login or sign up in order to post.