+ 1
Can someone please explain do while?
3 Answers
+ 3
let's try an example to know
int x=0;
int y=3;
do {
x= x+1;
} while (y < 3)
Console.WriteLine(x);
now x value will be 1 because old value = 0 and we add 1 to it.
it means do while excutes the code once at least before check about the condition.
so first we increment x value then check about the condition if y<3 and we find the condition is false then we exit the loop and won't continue.
if the condition is true then we loop another time ... etc
+ 2
do-while that's: execute the block statement at least once, than check condtion
if condition true, repeat block statement and so on, until condition false.
with this loop we know that block statement wil be executed at least once no matter what the condtion.
+ 2
code will repeat in the do block and be outputed in the console until the while condition is met