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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Labeeled Problem" Watch "Labeeled Problem" New topic
Author

Labeeled Problem

Micheal John
Ranch Hand

Joined: Nov 01, 2006
Posts: 344



Why this code is not compiling? and stating int j = 0 is not a staement


Micheal John
SCJP 1.4 (86%), SCWCD 1.4 (86%), SCBCD 1.3 (85%), SCDJWS (Just Started...) - Satisfaction Lies in Our EFFORT, Not in the ATTAINMENT
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
Michael,
I am also surprized why it is giving compilation error.I have tried to find something reg this in JLS and the most I finds is that you can label any statement.
Can anyone ,Please help?


~Sanjeev Singh<br />SCJP 1.5
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9622
    
    2

A labelled statement should be followed by a while loop or a for loop. Applying a label to any other statement will produce a compiler error.


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Maneessh saxena
Ranch Hand

Joined: Oct 03, 2006
Posts: 125
Hi guys,
You can never declare a variable in a lebeled block.whereas you can assign it a value if you previously declared it.

I hope this will help
Regards Maneesh Saxena


SCJP 1.4, SCWCD 1.5
Maneessh saxena
Ranch Hand

Joined: Oct 03, 2006
Posts: 125
Originally posted by Jothi Shankar Kumar Sankararaj:
A labelled statement should be followed by a while loop or a for loop. Applying a label to any other statement will produce a compiler error.


sorry my dear you are bit confused,as i said previously You can never declare a variable in a lebeled block.whereas you can assign it a value if you previously declared it.
class Q28fd {
public static void main(String[] args) {
int j;
int counter = 0;
l1:
for (int i=0; i<10; i++) {
l2:{
j = 0;//Compile Time Error
while (j++ < 10) {
if (j > i) break l2;
if (j == i) {
counter++;
continue l1;
}
}
}

}
System.out.println(counter);
}
}


I hope this will help
Regards Maneesh Saxena
Maneessh saxena
Ranch Hand

Joined: Oct 03, 2006
Posts: 125
Please ignore written "Compile Time Error" because it will compile & runs fine .this is to clear your confsion.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Labeeled Problem