Outline for January 17, 2018

Reading: §5


  1. Iteration
    1. Definite loops: execute a specific (definite) number of times
    2. Indefinite loops: execute until a general condition is false
  2. For loops
    1. General form: for i in iterator
    2. Iterator is either list or something that generates a list
    3. Very common form: for i in range(1, 10)
  3. range() in detail [for.py]
    1. range(10) gives 0 1 2 3 4 5 6 7 8 9
    2. range(3, 10) gives 3 4 5 6 7 8 9
    3. range(2, 10, 3) gives 2 5 8
    4. range(10, 2, -3) gives 10 7 4
  4. Program: counting to 10 [toten.py]
  5. Program: sum the first 10 squares [sumsq.py]
  6. Program: Fibonacci numbers [fib.py]

Matt Bishop
Department of Computer Science
University of California at Davis
Davis, CA 95616-8562 USA
Last modified: Version of January 10, 2018
Winter Quarter 2018
You can get a PDF version of this