This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "For loop" Watch "For loop" New topic
Author

For loop

kiran goud
Greenhorn

Joined: Apr 21, 2004
Posts: 23
Why the below program giving compiler - error saying 'l2: is not valid'.


(code tags added)
[ May 20, 2004: Message edited by: Barry Gaunt ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
To get this to work you have to label a block. Add pair of {} thus:


Check out the JLS for labels, break, and continue


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Ana Abrantes
Ranch Hand

Joined: Sep 04, 2003
Posts: 43
Because a label must be used with a loop and "l2" is set before a variable declaration not a loop.
Make this change to compile:


Ana<p>SCJP 1.4
kiran goud
Greenhorn

Joined: Apr 21, 2004
Posts: 23
Hi Barry ..

Iam getting the same result with both solutions ....

Thx
kiran
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
What compiler version are you using?
kiran goud
Greenhorn

Joined: Apr 21, 2004
Posts: 23
1.4 version ...

What difference did you find BARRY in both the solutions ...

Thanks
Kiran
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
1.4? Can you type "java -version" and let me know what you get.

I'm using 1.4.2-b28.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Hang on! Do you mean you no longer get a compilation error? Or do you mean when it runs you get the same result?
[ May 20, 2004: Message edited by: Barry Gaunt ]
 
 
subject: For loop
 
Similar Threads
loops & labels
loop
Labeeled Problem
Error while Running Code
Problem with labeled break