Lecture 4: Loops

Optional reading: chapter 5.

while and do while loops

video

Key ideas:

  • loop control variable
  • accumulator variables
  • compound assignment statements (+=, -=, *=, /=, %=)
  • ++a vs. a++
  • while vs. do while

for loops

video

Key ideas:

  • when to use for vs. while: when stopping point is known vs. not
  • for loops are just more compactly written while loops
  • nested loops

Lab 2 intro

video

Quiz info

video