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

Programming Practice: while loop

We do some live coding today and discuss some search algorithms that all feature the use, and the usefulness, of while loops.

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

Note that Part 3 (the third video) is optional extra material--look at it if you are interested in learning about search algorithms but it is not required.

Part 1: Word game, revisited

We revisit the word guessing game developed in Lecture 21. This time we use a while loop to repeatedly allow the user to guess and to process the guesses. Practice writing while loops as well as working with classes.

Part 2: Use while loop to check user input

Instead of assuming that the user provides appropriate input, we can check the input and re-prompt the user as many times as necessary! A while loop is super useful for this.

Optional Part 3: Search algorithms implemented using while

We briefly introduce the linear search and binary search algorithms. Linear search can be used to search for the first occurence of an item in a list. Use binary search when you are searching through a sorted list. Here we simply look at these algorithms as examples of the use and usefulness of while loops. If you will take the next programming course (CS 2110) later, you will learn much more about the algorithms, different implementations, and analysis.