Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

for loop

 
Nazma Panjwani
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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???


Thanks
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
W. Joe Smith wrote:Example of a for loop with empty condition:


This will not work, because there is one ; too many.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic