FOR syntax in C

Asked

Viewed 377 times

1

I’m new to the community, and I recently noticed in a C code, a FOR loop, with the following syntax. for(;;). Someone could explain that syntax to me. Thanks in advance.

1 answer

2


The for(;;) command is an infinite loop. To exit this loop you normally use the break command. Thus

for (;;)
{
  ...
  ...
  if (alguma_condicao)
    break; // sai do loop
  ...
  ...
}
  • Cool, thanks for answering. Very cool, this syntax of for, and very useful too. Thanks.

  • Then mark the solution as a response.

  • 1

    Excuse me, but such use of the command in this way is not legal. If you must remain in the loop until you see any conditions then use while or/while.

  • @anonimo, infinite loops are a common Pattern in C and C++...some people prefer "while (true)", others prefer "for(;)" .. , see here on page 60 of the book K&R they talking of the loop "for (;;)"

Browser other questions tagged

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