I having been staring at my screen for a while and I do really need an explanation for labeled loop in this scenario:
package com.misterkourouma.oca8.starter.test;
public class LabeledLoop{
public static void main(String[] args) {
int x = 5, j = 0;
OUTER: for (int i = 0; i < 3;) // -> This line has no curly braces but still compiles
INNER: do {
i++;
x++;
if (x > 10)
break INNER;
x += 4;
j++;
} while (j <= 2);
System.out.println(x);
}
}
But this one does not compile :
package com.misterkourouma.oca8.starter.test;
public class LabeledLoop2{
public static void main(String[] args) {
int x = 5, j = 0;
OUTER: for (int i = 0; i < 3;)
System.out.println("Labeled Loop");
INNER: do {
i++;
x++;
if (x > 10)
break INNER;
x += 4;
j++;
} while (j <= 2);
System.out.println(x);
}
}
All the INNER:
block are considered (I guess) as a single statement but It does not end with semicolon I wonder Why?
I am preparing for OCA 8 that's one of the reason I need to understand these weirds stuffs.
EDIT:
My question is on LabeledLoop example why does it compiles
Thanks in advance for your help.