预计阅读本页时间:-
喜欢这本书吗?请把本站加入广告屏蔽插件白名单
无弹窗/漂浮窗等广告形式,不影响阅读
General Loop Format
Factoring in break and continue statements, the general format of the while loop looks like this:
while <test1>:
<statements1>
if <test2>: break # Exit loop now, skip else
if <test3>: continue # Go to top of loop now, to test1
else:
<statements2> # Run if we didn't hit a 'break'
break and continue statements can appear anywhere inside the while (or for) loop’s body, but they are usually coded further nested in an if test to take action in response to some condition.
Let’s turn to a few simple examples to see how these statements come together in practice.