+ 1

Can someone please explain do while?

18th Jan 2017, 10:13 AM
aya hamoud
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
18th Jan 2017, 10:26 AM
Ahmad Hamdan
Ahmad Hamdan - avatar
+ 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.
18th Jan 2017, 10:40 AM
Greg Oboroceanu
Greg Oboroceanu - avatar
+ 2
code will repeat in the do block and be outputed in the console until the while condition is met
19th Jan 2017, 3:29 PM
Anselem Neymar
Anselem Neymar - avatar