From the course: Programming Foundations: Real-World Examples
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
While loops - Python Tutorial
From the course: Programming Foundations: Real-World Examples
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 burnt 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 for loop, I'll just start scrubbing this pan and I'll continue scrubbing until a specific condition is met. If 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 repeat that process again and I'll continue this process on and on and on until the pan is finally clean. Now I'm only checking the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.