From the course: Programming Concepts for Python

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

While loops

While loops

- The dishwasher just finished running, so I'm ready to put away the dishes into the cabinet. Uh-oh, most of the dishes in there look clean, but this pan had some burned food stuck to it that the dishwasher couldn't get off. I guess I'll have to clean it the old fashioned way. The process of scrubbing this pan belongs in a while loop because I don't know how many times I'm going to have to scrub it to get it clean. Rather than specifying how many times I'm going to scrub it before I begin, like you would with a four loop, I'll just start scrubbing this pan and I'll continue scrubbing until a specific condition is met, that the pan's clean, and then I can finally stop. Each round of the scrubbing is a two step process. First, I scrub the pan with a sponge, then I give it a quick rinse so I can see whether or not it's clean. Now I check it, nope, still dirty so I'll repeat that process again and I'll continue this process…

Contents