• Post Reply Bookmark Topic Watch Topic
  • New Topic

for loop  RSS feed

 
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
 
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.
 
Java Cowboy
Sheriff
Posts: 16081
88
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!