如何摆脱外循环? [英] How to get out of the outer loop?

查看:106
本文介绍了如何摆脱外循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

x = 0
while True: # outer loop
    while True:
        if x == 10:
            break
        print(x)
        x += 1





我尝试过的事情:





What I have tried:

x = 0
while True:
    while True:
        if x == 10:
            break
            break
        print(x)
        x += 1

推荐答案

重构你的代码:将两个循环移动到一个函数中,并用 return 替换 break
Refactor your code: move both loops into a function, and replace the break with a return.


这篇关于如何摆脱外循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆