Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "error" Watch "error" New topic
Author

error

jioy uilo
Greenhorn

Joined: Mar 29, 2003
Posts: 25
why error in the line after 12:
public static void main(String[] args) {
int counter = 0;
l1:
for (int i=0; i<10; i++) {
l2:
int j = 0;
while (j++ < 10) {
if (j > i) break l2;
if (j == i) {
counter++;
continue l1;
}
}
}
System.out.println(counter);
}
}
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
There cannot be intervening sentences bewteen a label an the loop it marks. That is "l2:" and "int j =0" have to be swapped.
Please ident your code using UBB.
[ May 23, 2003: Message edited by: Jose Botella ]

SCJP2. Please Indent your code using UBB Code
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
One thing more there can not be a label on a variable declaration.
Brian Joseph
Ranch Hand

Joined: May 16, 2003
Posts: 160
So where are all the legal positions for a label? In my book I only see it being applied on the same line as the loop construct.
 
 
subject: error
 
Similar Threads
another que from PGJC exam
Khalid's Mock Test.
For loop
Labeeled Problem
Error while Running Code