+ 2

What is difference b/w do while and while loop

29th Oct 2018, 4:29 AM
Vishal Yadav
Vishal Yadav - avatar
4 Respuestas
+ 5
do-while loop will execute a portion/block of your code before checking a condition. on the other hand a while loop will check before executing a code block. Is kinda like saying u want to go to ur friend's house to play video game. You could go to his home to check on him and find out he's not around, that's do-while Or you could call him on phone to find out if he's home before going; this is while.
29th Oct 2018, 5:20 AM
E_E Mopho
E_E Mopho - avatar
+ 2
do while always executes at least once. while(x) is the equivalent of if(x) {do... while(x)}
29th Oct 2018, 4:36 AM
Vlad Serbu
Vlad Serbu - avatar
+ 1
A do..while loop executes the instructions in its loop body before checking the loop condition. Contrary, a while loop checks the loop condition prior to executing instructions in its loop body, so you need to assess which of those loops best fits the requirement. Syntactically; do { // loop body } while(condition); Loop body is executed once, then condition is evaluated, the loop continues if condition evaluates to true. Therefore in do...while loop the loop body will be executed atleast once! Note, mind the semicolon after (condition). ============================== while(condition) { // loop body } Condition is checked first, loop body is executed only IF condition evaluates to true. - by Ipang
29th Oct 2018, 6:42 AM
Suraj Jha
Suraj Jha - avatar
+ 1
When we use while loop, it FIRST CHECKS whether the condition is true or false and then apply the loop. But if we use do_while loop, it will perform the loop at least one time, and then will check if the condition is true or false. -by veeresh maurya
29th Oct 2018, 12:47 PM
VEERESH MAURYA
VEERESH MAURYA - avatar