File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes use of for(;;) ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "use of for(;;) ?" Watch "use of for(;;) ?" New topic

use of for(;;) ?

Prashanth Naidu

Joined: Feb 13, 2004
Posts: 5
Hey all,
i dont understand what the use of a for loop in the following fashion:
for(; {....}
please clarify my doubt.. thank you
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

You mean with empty slots inside the parentheses? That's a "forever" loop. If there's nothing in there, then there'e no exit condition, and so the loop goes forever.
Personally I prefer to write this as "while (true)", but "for (;;)" is OK too.

[Jess in Action][AskingGoodQuestions]
Jeffrey Spaulding
Ranch Hand

Joined: Jan 15, 2004
Posts: 149
In addition to the previous posting.
I use this form ( i also prefer while( true ) { ... } ) when i can
have many different reasons to leave a loop with
I agree. Here's the link:
subject: use of for(;;) ?
It's not a secret anymore!