How can you break out of a loop in Python?

 To break out of a loop in Python, you can use the "break" keyword. It immediately stops the execution of the loop and jumps to the next line of code after the loop. Here's an example:


In this example, the loop prints the first five even numbers (0, 2, 4, 6, and 8). However, when the value of i becomes 1 (an odd number), the "break" statement is executed, and the loop stops. The program then continues with the next line of code after the loop.

Comments