Feb-15-2021, 04:01 AM
break
will only break out of the innermost loop.for outer in ["A", "B", "C"]: for inner in ["1", "2", "3"]: print(outer + inner) if True: break #exits the inner loop, but runs the next entry in the outer loop
Output:A1
B1
C1
It looks like for your program you want to exit the outer loop. The way I suggested to do that was set a variable, then break out of the inner loop and check in the outer loop if you should exit.all_done = False for outer in ["A", "B", "C"]: for inner in ["1", "2", "3"]: print(outer + inner) if True: all_done = True break if all_done: # if the inner loop set this variable, then we break the outer loop as well break
Output:A1