techbro
asked on
Label Usage
Can you explain why the code is not causing compiler error even though label "JILL" in line 6 is not used for a block?
However, if I use if (c > 3) break JILL; else c++; in line 6 instead of using JACK, then it causes compiler error.
What are the situations using labels are illegal?
The code is given below:
However, if I use if (c > 3) break JILL; else c++; in line 6 instead of using JACK, then it causes compiler error.
What are the situations using labels are illegal?
The code is given below:
void crazyLoop()
{
int c = 0;
JACK: while (c < 8)
{
JILL: System.out.println(c);
if (c > 3) break JACK; else c++;
}
}
What's the error you are getting?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks Gene_Cyp and mccarl
It makes sense now!
It makes sense now!