• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using "for loops"

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i need help to understand using "for loops" in java,because i cannot understand with condition.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

Basically, the condition in a for loop is evaluated to a boolean at the "top" (beginning) of each iteration. If true, then the loop body executes. If false, then the loop body does not execute.

See this Iteration section from Thinking in Java, and this section on The for Statement from The Java Tutorial.
 
Ranch Hand
Posts: 824
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by zawani ahmad:
i need help to understand using "for loops" in java,because i cannot understand with condition.



In for loop there is an initializantion part, a condition and an increment/decrement part. while the condition is satisfied. for loop executes it's body, As soon as the condition fails , it simply comes out from it's body.
[ May 27, 2006: Message edited by: Sunil Kumar Gupta ]
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Till the condition is satisfied.

Not "till," but "while."

You set up a loop with a condition like i < 12; and as long a i is less than 12, the loop is executed. When i reaches 12, then the loop is finished.
Is that any help?

CR

Additional: Remember the "condition" is the middle bit in the (), after the first ; and before the second ;.
[ May 27, 2006: Message edited by: Campbell Ritchie ]
 
Sunil Kumar Gupta
Ranch Hand
Posts: 824
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Campbell, I have corrected that.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic