Example 1:
public class ExampleWhile {
public static void main(String args[]) {
int a = 10, b = 20;
while (a < b)
{
System.out.println("hello");
}
System.out.println("hi");
}
}
Example 2:
public class ExampleWhile2 {
public static void main(String args[]) {
while (true)
{
System.out.println("hello");
}
System.out.println("hi"); // Compile time error saying unreachable statement
}
}
Why there is a compile time error in example 2 when example 1 runs without error?