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