+ 6

Out of do...while and while - which loop is efficient?

23rd Aug 2019, 5:28 PM
Harshita Verma
Harshita Verma - avatar
5 ответов
+ 6
It's not a matter of efficiency. Do while is used when you need to execute the function inside the loop AT LEAST once, because the condition is tested AFTER reading the lines inside the loop. While loop doesn't guarantee it because it skips the lines inside the loop if the condition returns false.
23rd Aug 2019, 5:41 PM
Tashila Pathum
Tashila Pathum - avatar
+ 4
You can use while instead of do-while because while is more generic however do-while executes before testing but while test before executing you can make while execute before testing by make an infinity loop with break condition
24th Aug 2019, 12:59 PM
ABADA S
ABADA S - avatar
+ 3
I googled this hope it helps In a while loop, the condition is tested first and then only the statements are executed. This means it provides better control right from the beginning. Hence, while loop is move efficient than do.. while loop.
23rd Aug 2019, 10:41 PM
Audu Peter Iko-Ojo
Audu Peter Iko-Ojo - avatar
+ 3
If the condition being checked is not satisfied before any iteration and the loop is not meant to be executed, do while is not just less efficient but the incorrect loop to use.
24th Aug 2019, 1:08 PM
Sonic
Sonic - avatar
0
It's mentioned in the sololearn read your quiz
25th Aug 2019, 11:02 PM
Imene Chihi
Imene Chihi - avatar