3.8.1 Hacks

Iteration:

An iteration is a repeating portion of an algorithm

  • repeats a specified number of times or until a given condition is met

Iteration example

EX: Seeing which mailbox the key fits in

  1. m = number of mailboxes
  2. Mailbox number 1-m
  3. Try key in mailbox
  4. Try next mailbox (next highest)
  5. Repeat until key fits
  6. Get your mail!

STOPPING CONDITION: use “break” to stop the iteration

3.8.2

Iteration Statement:

Iteration statements repeat statements 0+ times (in a loop) until the conditional to break the look is met

3.10 Hacks

Practice Problems

Hacks Part 1

Hacks Part 2

VOCAB:

  • 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
a <– EXPRESSION
  • Moves whatever “expression” is into the variable “a”
LIST <– []
  • Creates an empty list under the variable “LIST”
  • Allows you to add elements via “append”
  • Append is APPEND(LIST, x)
List[i]
  • “i” is where you would access the list (EX: index[1])
LENGTH(list)
  • Evaluates the number of elements in the list

Quiz Score