Hindi, asked by oendrila8, 11 months ago

difference between while loop and do while loop with an example in Java


oendrila8: computer

Answers

Answered by Sandhyathakur
2
Answer : · Only difference between these two loops is that, in while loops, test expression is checked at first but, in do...while loop code is executed at first then the condition is checked. So, the code are executed at least once in do...while loops.

siddhartharao77 Genius
Short note on while loop and do-while loop:

(i) A while loops condition is checked before each iteration.

(ii) A do-while loops condition is checked at the end of each iteration.


(i) While is an entry controlled loop.

(ii) Do-while is an exit controlled loop.


(i) While loop - Since condition is checked first,statements may or may not get executed.

(ii) Do-while loop - Since condition is checked later, the body statements will execute at at least once.


(i) While loop:

while(Expression)

{

// codes

}


(ii) Do-while loop:

do

{

//codes;

}

while(Expression);



Hope this information helps!
Similar questions