File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "for loop" Watch "for loop" New topic
Author

for loop

Himalay Majumdar
Ranch Hand

Joined: Sep 28, 2008
Posts: 324
Barring a forced exit, evaluatiing the iteration expression and then evaluating the conditional expression are always the last two things that happen in for loop--K&B

It also says "iterator expression" in for loop doesnt mean just an "increment expression" and so we can write this.




From the above doesn't it mean that "Hello" should be printed twice. Once before executing the body and once after the loop body executes.


SCJP 1.6, SCWCD 5.0, SCBCD 5.0 [loading..]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18546
    
  40

From the above doesn't it mean that "Hello" should be printed twice. Once before executing the body and once after the loop body executes.


Question. If the code was this instead...



Does it mean that the variable i will be incremented twice? Once before executing the body and once after the loop body exiecutes?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
No, only after executing the body.


SCJP 6
Himalay Majumdar
Ranch Hand

Joined: Sep 28, 2008
Posts: 324
Sorry. I missed that point. Thank you both
 
wood burning stoves
 
subject: for loop
 
Similar Threads
read next byte
MultiDimenaional Array sort
database coloumn updation problem
Java Beginner
labeled continue statement?