[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
loopWe 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.
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.
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
.
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