Lecture 4: Loops
Optional reading: chapter 5.
while
and do while
loops
Key ideas:
- loop control variable
- accumulator variables
- compound assignment statements (
+=
,-=
,*=
,/=
,%=
) ++a
vs.a++
while
vs.do while
for
loops
Key ideas:
- when to use
for
vs.while
: when stopping point is known vs. not for
loops are just more compactly writtenwhile
loops- nested loops