aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes For loop and Final Variables... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "For loop and Final Variables..." Watch "For loop and Final Variables..." New topic
Author

For loop and Final Variables...

Abhijit Kolhatkar
Greenhorn

Joined: Sep 14, 2006
Posts: 10
I think, for each iteration of FOR loop, a new FINAL variable is created..
I got following excrept in the J2SE tutorial on SUN:
Notice how the code declares a local variable within the initialization expression. The scope of this variable extends from its declaration to the end of the block governed by the for statement, so it can be used in the termination and increment expressions as well.

I think, a new variable is created for each iteration..
Petrus Pelser
Ranch Hand

Joined: Feb 20, 2006
Posts: 132
so it can be used in the termination and increment expressions as well.


Considering this statement, the variable can not be final.
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi ranchers,
are you talking about a for loop or a for-each loop?






Ah, yes there was this other thread.

Yours,
Bu.

[ October 09, 2006: Message edited by: Burkhard Hassel ]
[ October 09, 2006: Message edited by: Burkhard Hassel ]

all events occur in real time
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: For loop and Final Variables...
 
Similar Threads
Why final variable in enhanced for isn't acting final?
final objects in the enhanced loop
eligibility for gc
stack in loops
Final modifier in enhanced for-loop : How can this be?