I have two loops. I understand that I can use the break, continue and else statments after to break out of them, but because my loop has code also after the condition, which should only get executed for all the condition cases I think that it doesnt work. I would use code like this:
for i in range(10):
for j in range(10):
print(i*j)
if testfunction(i,j):
break
else:
continue # only executed if the inner loop did NOT break
break # only executed if the inner loop DID break
Because of the required continue statement for the outer loop this does not work because the nested loop is not the only code in the outer for loop.
for i in range(10):
for j in range(10):
if testfunction(i,j):
breaker = True
break
if breaker == True:
break
executionfunction(i,j) # this code should only be executed if i passed the test with all j's
How can I write this without using variables like breaker?