This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
public class Temp
public static void main(String args)
int i = 0;
for ( ; i<10; i++) ; // (1)
for (i=0; ; i++) break; // (2)
for (i=0; i<10; ) i++; // (3)
for ( ; ; ) ; // (4)
When I compile javac Temp.java, I get an error For the fourth System.out.println as "statement unreachable". Has it been at runtime I can consider that the fourth for loop is an infinite so the System.out.println is unreachable. This is compile time error.
As the for loop at line no. 4 is an endless loop so compiler will never be able to reach any statement after that for the compilation purpose and therefore an error is thrown stating it to be an unreachable statement.