简体   繁体   English

如何将 go 返回到 python 中 While True 循环内的代码点?

[英]How to go back to a point of code within a While True Loop in python?

I need my input 3 to be validated, therefore it needs to return back to input 3 if the "else block" is activated.我需要验证我的输入 3,因此如果“else 块”被激活,它需要返回到输入 3。 also "if block" must go back to input 1 thats why ive put continue.同样“if block”必须 go 返回到输入 1 这就是为什么我要继续。

while True:
    input 1
    input 2
      process
    input 3
       if result == "c';
             continue

       elif result == "e"
             break

       else:
           the code needs return back to input 3 until user enters "c" or "e"


How can implement this using python?如何使用 python 实现这个?

You can use flag variable to cope with nested loops.您可以使用标志变量来处理嵌套循环。 Such as:如:

flag = True
while flag == True:
    input('1')
    input('2')
    while True:
        result = input('3')
        if result == 'c':
            break
        elif result == 'e':
            flag= False
            break
        else:
            continue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM