4

I have to maintain a code, and came up with this:

for (;;) {
  //code
}

What would it do? I couldn't find documentation about it.

In a hunch I think it runs only once... but that would be useless...

JorgeeFG
  • 5,651
  • 12
  • 59
  • 92

4 Answers4

3

it is an infinite loop, similar in function as:

while(true) 
{
}
T McKeown
  • 12,971
  • 1
  • 25
  • 32
  • 4
    The most scary part is that I think I am responsible for this... lol. Might be something of my newbie things – JorgeeFG Apr 04 '14 at 18:21
  • 1
    hah! Doesn't it suck when you look at code you wrote in the past, and are all like... WTF is this supposed to do? Or... uhhh... so I hear... ;) – Andrew Barber Apr 04 '14 at 18:22
  • 1
    Oh I think I know why I did it... because I am checking for errors inside, and when some error is found, I have to exit and do not check the other errors... but there should be a better less scary way – JorgeeFG Apr 04 '14 at 18:25
2

Your code sample is an infinite loop. To terminate, the omitted code (//code) must exit the loop or the entire PHP script.

2

It's a for loop without initialization parameters, no breaking conditions and no increments/decrements/whatever on each iteration - think of it like for (nothing; nothing; nothing).

Unless you break it from the inside, it's going to run forever.

Shomz
  • 37,421
  • 4
  • 57
  • 85
1

For embedded code it is the main loop that does all the other sub process in a super loop scheme.

SamFisher83
  • 3,937
  • 9
  • 39
  • 52