while Statements

Execution rule:

  1. Evaluate the header’s expression.
  2. If it’s a true value, execute the (whole) suite, then return to step 1.

Iteration Demo - The Fibonacci Sequence

Designing Functions

Three characteristics of functions that are really important:

  • A function’s domain is the set of all inputs it might possibly take as arguments.
  • A function’s range is the set of output values it might possible return.
  • A pure function’s behavior is the relationship it creates between input and output.

A Guide to Designing Functions

  • Give each function eactly one job, but make it apply to many related situations
  • Don’t repeat yourself. Implement a process just once.
>>> round(1, 23)
>>> round(1.23, 1) # round to 1 decimal place
>>> round(1.23, 0) # roudn to integer

Generalizing Patterns with Arguments

The area example

Higher Order Functions

Generalizing over Computational Processes

A higher order function is a function that takes in another function as an argument.

Example, summation and make_adder

Locally Defined Functions

Functions defined within other function bodies are bound to names in a local frame.

An operator is any expression that evaluates to a function. So, in


make_adder(1) is the operator.

Hey! Thanks for reading :P I just want to let you know that if you enjoyed this, you might also like this post on Lecture 3 – Controls.


I'm Bobby Yan, a programmer, music lover and web developer. I am currently working on IB Notes, a website with useful and concise study guides and notes for IB students. I have also built the Spanish Vocabulary Builder iOS app to help Spanish learners.

If you enjoyed this article, you should follow me on Twitter or sign up to get an email whenever I write something new:

Share this article with your friends: