+ 5

How is a do while loop different from a while loop?

26th Apr 2017, 4:49 AM
Nuradin Mohamed Ali
Nuradin Mohamed Ali - avatar
2 odpowiedzi
+ 14
a while loop first checks the condition then executes the body, so if the condition is False it never executes. Do while first executes the body and the checks the condition, so even if the condition is False it will execute once.
26th Apr 2017, 5:26 AM
Nikolay Nachev
Nikolay Nachev - avatar
+ 3
while is an entry-controlled loop, which means that iteration(s) will take place only if the condition of the loop is true. e.g. while(condition) { :Loop_body } do-while on the other hand is a exit-controlled loop, which means that the loop body code will be executed once, after that the condition is evaluated, so even if your condition is wrong, no matter what, your loop will be executed once atleast. e.g. do { :Loop_body } while(condition);
26th Apr 2017, 6:05 AM
Tushar Ranjan Behera