课程: Programming Concepts for Python

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Break statements

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 and 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…

内容