-3

How does an empty for works?

I have seen this code (and works perfectly)

for(;;) {

And I can't comprehend how is this working or why

Idos
  • 15,053
  • 14
  • 60
  • 75
Roucher
  • 151
  • 7
  • 1
    C++ is full of special strange rules... this is just one of them. – 6502 Dec 06 '15 at 16:09
  • Read it like this: `for nothing, until no condition, and nothing changes`. Logically that would be `true` always. And hence it's an endless loop. – DeiDei Dec 06 '15 at 17:32
  • @6502 - there's nothing special here. It just falls out from the way `for` is defined. – Pete Becker Dec 06 '15 at 19:30
  • @PeteBecker: exactly... and for example I can write `while()` too or use `if()` to mean an always-true condition. Not. – 6502 Dec 06 '15 at 20:14
  • @6502 - yes, the specifications for `if` and `while` are different from the specification for `for`. Since they do very different things, that is neither "special" nor "strange". – Pete Becker Dec 06 '15 at 21:47

1 Answers1

0

It is exactly like while(true).
It skips all the conditions so it just empty-executes since in for the expressions are all optional (i.e. you don't have to provide them if you choose not to).

Idos
  • 15,053
  • 14
  • 60
  • 75