What will be the result of attempting to compile and run the following program?.
public class Main { 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) } }
Select the one correct answer.
(f)
The code will compile without error, but will never terminate when run.
All the sections in the for header are optional and can be omitted (but not the semicolons).
An omitted loop condition is interpreted as being true.
Thus, a for loop with an omitted loop condition will never terminate, unless a break statement is encountered in the loop body.
The program will enter an infinite loop at (4).