Skip to content
Advertisement

While loops using break and continue statements

I’m beginner. What is break and continue statement used for for a while statement?

while:
    break
    continue

Advertisement

Answer

These two key words can be used in a loop to change how it behaves. The break statement terminates the loop and moves on the next executable statement. The continue statement skips the rest of the code for the current pass of the loop and goes to the top to the test expression.

You may find this link helpful: Here

Example:

while True:
    if condition:
        break  # exits loop
    if condition:
        continue  # skips statements in ... and goes back to top
    ...

This loop would iterate until it reaches a break statement.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement