Which is Efficient and fast! while, do-while or for loop ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Which is Efficient and fast! while, do-while or for loop ?

14th Aug 2016, 6:00 AM
Ashish Kumar
Ashish Kumar - avatar
2 Answers
+ 2
Depends on the code and situation. Explain or provide an example. most often then not you can make each one work for you however choose the one that makes sense to you. if you want a nested loop and know how many time to reiterate use for loop. if you need to at least run the function once regardless if the condition is met run the do while and if you want to only run the code if a condition is met do a while loop.
14th Aug 2016, 6:34 AM
Chris Cook
Chris Cook - avatar
- 1
they have different reasons to use. its not about efficiency
14th Aug 2016, 6:34 AM
Máté Lencsés
Máté Lencsés - avatar