aspose 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
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: 19073
    
  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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: for loop