break is used to stop the loop immediately.

example

i = 1
 
while i <= 5:
    if i == 3:
        break
    print(i)
    i += 1

output

1
2

Note

  • break exits the loop immediately
  • Loop stops even if the condition is still True

<< Python While Loop | Python Continue >>