Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

for loop

 
Himalay Majumdar
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Marshal
Pie
Posts: 21197
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, only after executing the body.
 
Himalay Majumdar
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry. I missed that point. Thank you both
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic