'Warning: The label [number] is never explicitly referenced
boolean t = true;
first:
{
second:
{
third:
{
System.out.println("Before the break");
if (t) {
break second;
}
System.out.println("This wont execute");
}
System.out.println("Neither this one");
}
System.out.println("this will execute");
}
In the code, before "first" and before "third" there shows a warning: The label first/third is never explicitly referenced. Can ypu tell why is this warning showing?
Solution 1:[1]
that is just because you are never referring them in your code
as you referred second by following
if(t) break second;
Solution 2:[2]
Warning: Never explicitly reference
First of all this warning shows because of the label is never explicitly referenced. Though there is no role of that label, you still using the label in your code. and the main problem is here that the label will never closed. So, if you want to turn off the warning then you use 'break' statement.
Boolean t = true;
first:
{
second:
{
third:
{
System.out.println("Before the break statement.");
if(t)
{
break second;
}
System.out.println("This won't execute.");
break third;
}
System.out.println("This won't execute.");
}
System.out.println("This is after second block.");
break first;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | dev2d |
| Solution 2 | Soumyadip Majumder |
