For a loop without parameters in Java

I look at another user's code and I found this piece of code:

for (;;) { 

I am not a Java expert; what does this line of code do?

At first I thought it would be creating an infinite loop, but in the most MOST class this programmer uses

 while(true) 

Which (correct me if I am wrong) is an infinite loop. Are these two identical? Why did someone change their method to repeat the same process?

Any insight will help,

Thanks!

+7
source share
3 answers

Remember that there are three for () conditions: [1] termination [2] termination and [3] increment. Since the term clause is empty, the loop never ends. This is directly taken from C. syntax

+12
source

These two lines will have the same effect. I can’t think of a good reason to use the first if you don’t want to confuse people. I think these are fewer characters.

+6
source

they are completely identical, the only real difference would be either preference (the design can be typed a little faster)

or the value indicates that there is some iteration that breaks into a break or return, and the while loop indicates a repeating section of the same thing until a meaningful result appears.

+5
source

All Articles