I'm brand new to coding and now that I've started using loops I'd like to know which ones I should normally use and when.
CodePudding user response:
Since you're just starting off, what should be relevant to you is that a do-while
loop will always execute at least once while a while
loop can run zero times.
CodePudding user response:
no specific answer to this, anything that can be achieved with for
loop can also be achieved with while
or do-while
.
Here are some general notes :
for
is usually used with arrays, or when the number of loops is known.while
anddo-while
, are used when I need to loop until a condition has been met.do-while
will execute the code at least once, even if the condition is false.