*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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...