1

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
asked Aug 14, 2020 at 2:13
0

2 Answers 2

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.

answered Aug 14, 2020 at 2:13
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.