What will the following program print?
class Test{ //from w ww. j a v a 2s .c o m public static void main (String args []){ int var = 20, i=0; do{ while (true){ if ( i++ > var) break; } }while (i<var--); System.out.println (var); } }
Select 1 option
Correct Option is : A
When the first iteration of outer do-while loop starts, var is 20.
The inner loop executes till i becomes 2 1.
The condition for outer do-while is checked, while( 22 < 20 ), [i is 22 because of the last i++>var check], thereby making var 19.
As the condition is false, the outer loop also ends.
19 is printed.