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 for loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "for loop" Watch "for loop" New topic

for loop

Nazma Panjwani

Joined: Jan 17, 2010
Posts: 17

What does this statement mean....In Java, a while loop cannot have an empty condition but a for loop can. Can you give examples please???

W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
Example of a for loop with empty condition:

That for loop is perfectly acceptable, although it is an infinite loop. However, the following while loop is not valid:

This will not work. You have to have some sort of boolean, or expression that results in a boolean, in the while condition.

When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

W. Joe Smith wrote:Example of a for loop with empty condition:

This will not work, because there is one ; too many.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: for loop
jQuery in Action, 3rd edition