Have you tried to stop a loop or continue a loop with or without a condition.
So this is the recipe on how we can use CONTINUE and BREAK statement within a loop in Python.
We have only imported numpy which is needed.
We have created a while loop after creating an object. We have made conditions for keep the loop working and to stop the loop. We can stop the loop by using break function.
running = True
s = random.randint(0,5)
if s < 3:
print(s, ": It is too small, starting again.")
if s == 4:
running = False
print("It is 4! Changing running to false")
if s == 5:
print("It is 5! Breaking Loop!")
We get the output as:
0 : It is too small, starting again. 2 : It is too small, starting again. It is 5! Breaking Loop!