0

I've seen in a java program the following syntax :

for(;;){

}

What does it means ? I didn't see the explanation on internet after some researches.

Is it the same thing that a while(true) loop?

Edit :

Sorry for duplicate, when your type " for(;;) " in your researches you doesn't find the information wanted. Thanks for reply.

Corentin
  • 325
  • 5
  • 21
  • 2
    Were you not able to verify this? – zEro Jul 31 '13 at 11:43
  • 2
    I never understood the existence of this while `while(true)` exists. Well, it's just me. – Leri Jul 31 '13 at 11:43
  • @PLB, the while(true) (in C/C++: while(1)) is usefull for something that has to run "infinitely". The actual interruption of the loop in such cases is handled in its body. Low-level example: imagine you have a microcontoller that once powered on has to run and run, checking input from its pins and sending signals to other parts of the system. There are situation in high-level programming languages (such as Java) where something like this is also needed: waiting for input by the user. – rbaleksandar Jul 31 '13 at 11:56

3 Answers3

9

This:

for (;;) {
}

It's a shorthand for an infinite loop, equivalent to this:

while (true) {
}

In fact, as show in this answer both are completely equivalent at the bytecode level.

Community
  • 1
  • 1
Óscar López
  • 232,561
  • 37
  • 312
  • 386
1

The three expressions of the for loop are optional.

an infinite loop can be created as follows:

// infinite loop

for ( ; ; ) {

    // your code goes here
}
swapy
  • 1,616
  • 1
  • 15
  • 31
Sandip Lawate
  • 456
  • 3
  • 11
0

It is an infinite loop and yes, it is the same as

while(true) {

}

But considering the complexity" of your question I do believe you could have just written a simple Hello World programm with this structure in it and see what happen, right? ;)

Atish Kumar Dipongkor
  • 10,220
  • 9
  • 49
  • 77
rbaleksandar
  • 8,713
  • 7
  • 76
  • 161