[We hope that you can view the videos! However, if your internet connection is too slow for viewing videos, download the audio file (mp4) and the slides (pdf). Then you can listen to the audio as you go through the slides.]

while loop

We return to the topic of iteration! A while loop allows us to deal with indefinite iteration--iterating an unknown (or not easily knowable) number of times until some stopping condition is reached.

Slides for all 3 videos of this lecture: individual slides for viewing and a "6-up" version for printing.

The answers to the questions asked during this lecture are in a separate file at the end of this page.

Part 1: Indefinite iteration, syntax, and flow

When do we use a while loop? When we deal with indefinite iteration. We learn what is indefinite iteration and the syntax and flow of the while loop.

Part 2: Choose while or for?

How could we choose between the two kinds of loops? We look at some examples and discuss the advantages and disadvantages of using while.

Part 3: How to set up a while loop?

We suggest some steps for setting up a while loop and use them to write a number guessing game. Try writing your own version as well! There are different ways to set up a while loop for the game.

Answers to the questions asked during lecture: pdf