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 and Final Variables... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets 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
 
Don't get me started about those stupid light bulbs.
 
subject: For loop and Final Variables...
 
Similar Threads
Why final variable in enhanced for isn't acting final?
Final modifier in enhanced for-loop : How can this be?
final objects in the enhanced loop
stack in loops
eligibility for gc