How many times the following loop will gets executed? What is the output of
the same?
int counter=1;
do
{
System.out.printIn(counter);
} while ( counter ++ < 5 );
Solution
When counter =1:
print:-
1
When counter =2:
print:-
1
2
When counter =3:
print:-
1
2
3
When counter =4:
print:-
1
2
3
4
When counter =5:
print:-
1
2
3
4
5
So output is: 1 2 3 4 5