简体   繁体   中英

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. also "if block" must go back to input 1 thats why ive put continue.

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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