I'm beginner. What is break and continue statement used for for a while statement?
while:
break
continue
Trenton McKinney
63.2k41 gold badges170 silver badges214 bronze badges
2 Answers 2
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.
Sign up to request clarification or add additional context in comments.
Comments
continue is used to skip a particular iteration of the loop
while(i<5):
if i == 3:
continue
print(i)
i++
break is used to get out of a loop
while(i<5):
if i == 3:
break
print(i)
i++
alani
13.2k3 gold badges18 silver badges34 bronze badges
answered Aug 14, 2020 at 2:29
Aaradhanah Appalo Eleven
318 bronze badges
Comments
lang-py