1

I am wondering if you can restart, in python, Loop A while you are in Loop B. For example:

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

With ??? representing the code to go back and repeat Loop A. Please, I really need this answer. For those of you who have or will answer, thank you!

Aarav Dave
  • 41
  • 1
  • 11
  • 1
    Do you mean `break`? – DYD Apr 01 '20 at 01:30
  • Why not just `break`? – Sunny Patel Apr 01 '20 at 01:30
  • 1
    Possible duplicate of https://stackoverflow.com/questions/653509/breaking-out-of-nested-loops - the question itself is answered by `break`, but if there was other logic involved "go repeat A" is not the same thing as "stop current loop" – Cireo Apr 01 '20 at 01:35

1 Answers1

2

In python, you can use break to exit the loop you are in.

while True:     #Loop A
   while True:      #Loop B
       ans = int("Question")
       if ans == "y":
           print("Something")
       else:
           break
Aaron Jones
  • 1,140
  • 1
  • 9
  • 26