• 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
Sheriff
Posts: 15758
74
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.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!