r/javahelp • • Aug 09 '22

what does for(;;) mean?

Just like the title asks, what does for(;;) mean? A double semicolon in a for loop, I found it in some code I'm trying to understand and Google can't seem to answer my question. Thanks!

17 Upvotes

14 comments sorted by

View all comments

25

u/NautiHooker Software Engineer Aug 09 '22

Equivalent to

while (true)

You omit the iteration variable, its incrementation and the exit condition, which means it becomes an endless loop that needs to be ended with a break/return statement somewhere.

If I am not mistaken this way of writing such loops comes from older C like languages that didnt have the option for while(true).

8

u/Encryp73r Aug 09 '22

I see how it works now, the while(true) comparison helped. That's why they use a return statement. Thanks!

2

u/jonathancast Aug 09 '22

C can do while (1), or while (TRUE) with a macro. More likely for (;;) is shorter.