Key Concepts

Review core concepts you need to learn to master this subject

break Keyword

numbers = [0, 254, 2, -1, 3] for num in numbers: if (num < 0): print("Negative number detected!") break print(num) # 0 # 254 # 2 # Negative number detected!

In a loop, the break keyword escapes the loop, regardless of the iteration number. Once break executes, the program will continue to execute after the loop.

In this example, the output would be:

  • 0
  • 254
  • 2
  • Negative number detected!
Loops
Lesson 1 of 2