1

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?

3
  • input X` is not valid python. What do you intend? To go back, you would use another loop and check result. Commented Nov 24, 2022 at 19:09
  • unable to use another loop as the continue statement in the "if block" needs to belong to the initial while true loop @user19077881 Commented Nov 24, 2022 at 19:36
  • Your question is not very clear. Can you please elaborate with an example flow? You can also put actually code for your input variables. Commented Nov 24, 2022 at 20:03

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.