From the course: Programming Foundations: Real-World Examples

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Break statements

Break statements - Python Tutorial

From the course: Programming Foundations: Real-World Examples

Start my 1-month free trial

Break statements

- Now that all of my dishes are finally clean, I'm ready to unload the dishwasher and put the clean dishes into the cabinet. This is a perfect operation to execute using a for loop, because I know that there are 20 clean dishes in the dishwasher, and I plan to unload all of them. So, I'll count aloud as I unload each one. I'll pick up the first dish, put it away. That's one. I'll pick up the second dish, and put it away as well. That's two. I'll pick up the third dish. Well, my cabinet is full, which means I need to stop this process, because there's no space left. I had originally planned to put away all 20 dishes, but because this happened, I'll need to exit my for loop early, and leave the unprocessed dishes in the dishwasher. If I had checked the cabinet before I started, I might have seen that it only had space for two dishes, which is way less than the number of dishes in the dishwasher, and in that case, I could have modified my for loop to only process two dishes instead of…

Contents