How do I know which loops to use? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How do I know which loops to use?

Whenever I get a programming exercise, I have difficulty with selecting which loop to use. Do you having any tips or guidelines I could use to select the right loop to use?

18th Mar 2020, 3:44 AM
Jay
5 Answers
+ 5
When you know the number of iterations then use FOR LOOP. When you don't know the number of iterations then use WHILE LOOP. Use DO WHILE LOOP if you feel that something has to be executed atleast once. For conditional statements you can replace your 'IF ELSE' ladder with SWITCH.
18th Mar 2020, 3:51 AM
Avinesh
Avinesh - avatar
+ 6
//If you see course on java its nicely mentioned how and where to use this loops while,for and do while https://www.sololearn.com/learn/Java/2146/ https://www.sololearn.com/learn/Java/2147/ https://www.sololearn.com/learn/Java/2206/
18th Mar 2020, 3:53 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 5
If you familiar with c or c++ then easily understood that but if you don't know c/c++ then show videos by Durga sir on YouTube.
21st Mar 2020, 1:29 AM
Ketul Patel
Ketul Patel - avatar
+ 3
Avinesh thank you for that tip.. I will definitely use that
18th Mar 2020, 3:55 AM
Jay
+ 2
Sudarshan Rai 👑 thank you, I'll surely check them out
18th Mar 2020, 3:55 AM
Jay