DEV Community

Jay
Jay

Posted on

Break

break is used to exit a for loop or a while loop, whereas continue is used to skip the current function, and return to the "for" or "while"statement.

e.g:

count = 0
while True:
    print(count)
    count += 3
    if count >= 7:
        break
Enter fullscreen mode Exit fullscreen mode
  • continue
for x in range(1,20,4):
    # Check if x is even
    if x % 2 == 0:
        continue
    print(x)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)