+ 6
Out of do...while and while - which loop is efficient?
5 Réponses
+ 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.
+ 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
+ 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.
+ 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.
0
It's mentioned in the sololearn read your quiz