Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes for loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "for loop" Watch "for loop" New topic
Author

for loop

Mohd Abrar Khan
Greenhorn

Joined: Jan 20, 2010
Posts: 18


the third part of the for loop is the iteration, i just wanted to know in the above code does the line 3 evaluates the output or its just that the iteration starts after the condition is passed.

i tried running without line 3 and the result is never ending, so how does the condition operator gets checked and starts the iteration.

Abrar
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317


This is the condition.

1) set a to 1.
2) Check if b is equal to 1.
3) enter the loop and process it.
4) finish off the third part of the iteration i.e print.

For the next run, a is still 1 while b is 2 ( due to b=b-a). This will print once more.

For the third run, a =1 and b is 1 too. the condition fails and the loop exits.

Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066



This is same as your code.... Mohd Abrar Khan, Your question isn't clear well.......


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: for loop