0

If I have a body of code that looks like this:

for ship in ships.shipLengths.key():
    while(True):
        # Code
        while(True):
            # Code
            while(True):
                # Code

If I am currently in the 3rd while loop is there a way for me to get back to the first while loop?

Taku
  • 31,927
  • 11
  • 74
  • 85

1 Answers1

0

I agree with @Aluan and @Daniel that is not a good practice to write the code that way.

Anyway, if you still want to do it, here is a way:

x = True
for ship in ships.shipLengths.key():
    while condition1:
        # Code
        while condition2 and x:
            # Code
            while condition3 and x:
                # Code
                if goto_1st_while:
                    x = False
                    continue
                # The code here will not run when goto_1st_while is True
            if not x:
                continue
            # The code here will not run when goto_1st_while is True
H Rayan
  • 130
  • 1
  • 7