This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP 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
Pie
Posts: 15438
41
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