0

I have a doubt in do while loop ,as in do while loop condition is given at the bottom so statement is executed first .

for printing 3 starting numbers what should be the condition in while if we use do while loop?

31st Jan 2017, 1:30 PM
kanchan
2 Antworten
+ 2
Since you want to print 1,2,3, there is more than one way. For example: int x = 1; do{ System.out.println(x); x++; } while(x<4); or int x = 1; do{ System.out.println(x); x++; } while(x<=3);
31st Jan 2017, 1:57 PM
Deddy Tandean
+ 1
do runs code at least once before testing the condition so consider using another loop or reverse the conditions result
31st Jan 2017, 2:41 PM
Andre van Rensburg
Andre van Rensburg - avatar