Home > OS >  I know that for while and do loops are very similar but in what specific scenarios would I choose on
I know that for while and do loops are very similar but in what specific scenarios would I choose on

Time:06-19

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 :

  1. for is usually used with arrays, or when the number of loops is known.
  2. while and do-while, are used when I need to loop until a condition has been met.
  3. do-while will execute the code at least once, even if the condition is false.
  • Related