• Post Reply Bookmark Topic Watch Topic
  • New Topic

Explanation of a java code  RSS feed

 
henry joe
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please guys,

I can't seem to understand why the for loop in this code has the conditional part in which the code checks that cnt<2.. I don't get that part. why is that in the code?





 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
henry joe wrote:I can't seem to understand why the for loop in this code has the conditional part in which the code checks that cnt<2.. I don't get that part. why is that in the code?

Because a for loop is meant to run for a defined range of values. To do that you have to tell the app what the range of values you want are. And that is what the condition part of the statement does.

See: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!