Why use for loops?:
- more expressive, succinct, and compact when expressing loops that execute a known number of iterations
forloops convey more intent thanwhileloops that execute a known number of iterations
How to use for loops?:
- Things to note:
- any variable used in
expression1,expression2, orexpression3will need to be previously declared expression1is used to initialize some parameter, typically called an indexexpression2is a condition that must betruefor the loop to continue executionexpression3is is used to alter the value of the parameter initially assigned byexpression1