Link to home
Create AccountLog in
Avatar of techbro
techbroFlag for United States of America

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:

void crazyLoop()
{
	int c = 0;
	JACK: while (c < 8)
	{
		JILL: System.out.println(c);
		if (c > 3) break JACK; else c++;
	}
}

Open in new window

Avatar of Gene_Cyp
Gene_Cyp

What's the error you are getting?
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of techbro

ASKER

Thanks Gene_Cyp and mccarl
It makes sense now!