Notes

Section Objectives:

  • Express an algorithm that uses iteration without using a programming language
  • Determine the result or side effect of iteration statements
  • Write iteration statements

Vocab

  • Iteration: a repeating portion of an algorithm, repeats a specified number of times or until a given condition is met

  • Iteration Statements: change the sequential flow of control by repeating a set of statements zero or more times, until a stopping condition is met

  • Repeat Until: if the condition evaluates to true initially, the loop body is not executed at all, due to the condition being checked before the loop

  • Complete Traversal: All elements in a list are assessed

  • Partial Traversal: Only a given portion of elements are assessed

  • Iterative Traversal: When loops are used to iterate through a list and to access each single element at a time.

Notes

  • Iteration is part of an agrothim
  • Keeps looping until problem is finshed
  • range excludes that last value
  • insert( ) allows a value to be inserted into a list at index i
  • append( ) allows a value to be added at the end of a list
  • remove( ) allows an element at index i to be deleted from a list
  • length( ) returns the number of elements currently in a specific list

Hacks Unit 3 Section 3.8.1

1

  • Iteration is when a loop repeats steps until a condtion is met

2

  • Cycle through water animals till nemo is found

3

water = ["whale", "trout", "shark", "bass", "nemo"]
for fi in water:
    if i == "nemo":
        print("nemo is here")
        break
    else:
        print(i + " is not nemo")
whale is not nemo
trout is not nemo
shark is not nemo
bass is not nemo
nemo is here

Hacks Unit 3 Section 3.8.2

1

  • Iteration Statements are statments that go through a process of steps until a condition is met

2

for i in reversed(range(1,11)):
    print(i)
10
9
8
7
6
5
4
3
2
1

3

numbers = 0
n = 1
while numbers < 80:
    numbers = 3+(n-1)*13
    n = n + 1
    print(numbers)
    
3
16
29
42
55
68
81

Hacks Unit 3 Section 10

nums = [10, 15, 20, 25, 30, 35]
mnums = min(nums)
for i in nums:
    if i > mnums:
        mnums = mnums + 5
    else:
        mnums = mnums + 5
print(mnums)
40

quiz