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?
2 ответов
+ 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);
+ 1
do runs code at least once before testing the condition so consider using another loop or reverse the conditions result