首页 > 解决方案 > Python中的循环循环

问题描述

我想知道您是否可以在循环 B 中时在 python 中重新启动循环 A。例如:

while True:     #Loop A
    while True:      #Loop B
        ans = int("Question")
        if ans == "y":
            print("Something")
        else:
            ???

和 ???代表代码返回并重复循环A。拜托,我真的需要这个答案。对于那些已经或将要回答的人,谢谢!

标签: pythonloops

解决方案


在python中,您可以使用break退出您所在的循环。

while True:     #Loop A
   while True:      #Loop B
       ans = int("Question")
       if ans == "y":
           print("Something")
       else:
           break

推荐阅读