java - Break Label is missing even when the label is inside the enclosing loop -
can tell me why compiler says label missing in below code:
case1:
error: label missing
void crazyloop() { int c = 0; jack: while (c < 8) { jill: system.out.println(c); if (c > 3) break jill; else c++; } }
here jill
reachable have declared jill
inside jack
, not outside jack
.
case2:
error: c cannot resolved. , if :
void crazyloop() { jill:int c = 0; jack: while (c < 8) { system.out.println(c); if (c > 3) break jill; else c++; } }
the compiler says c
cannot resolved variable.
can please explain happening ?
from jsl 14.15. break statement
a break statement label identifier attempts transfer control enclosing labeled statement (§14.7) has same identifier label
so error caused break statement not referring label of loop. also, statements may have label prefixes. see documentation
the following code compiles successfully:
void crazyloop() { int c = 0; ill: c= 0; jack: while (c < 8) { system.out.println(c); if (c > 3) break jack; else c++; }
Comments
Post a Comment