Programmer Coding

Break / Continue Statements

Control Statements(Break / Continue Statements)

 

Statements used to govern loops and exchange the route of iteration are known as manipulate statements. all of the gadgets produced in the local scope of the loop are deleted whilst execution is finished.

Python presents the following manage statements. we are able to discuss them later in element.

allow us to speedy pass over the definitions of those Break/Continue control statements.

  • Break statement
  • Continue statement
  • Pass statement

 

Break Statements?

A break statement is used internal each the whilst and for loops. It terminates the loop right now and transfers execution to the new statement after the loop. for instance, have a look at the code and its output beneath:

Example

num = 0
for num in range(10):
    if num == 5:
        break
    print('Number is', num)

Output

Number is 0
Number is 1
Number is 2
Number is 3
Number is 4

Continue Statements

The continue statement causes the loop to skip the current execution at some point and continue with the next iteration. It does not terminate the loop like the output statement, but continues with the next function.

Example

for i in range(0, 5):
    if i == 3:
        continue
    print(i)

Output

0

1

2

4

Pass Statements

In cases where the user does not know what to write, he can only write on that line. This bypass is sometimes used when the user does not want to do it. Therefore, users only need to drop a point that is not allowed, such as circles, function points, class points, or an expression. So user can avoid this error by using pass statement

Example

list=['Ramkrishna', 'Satyam', 'Shubham', 'Jitu','Vishnu']
for i in list:
    if(i =='Jitu'):
        pass
    else:
        print(i)

Output

Ramkrishna

Satyam

Shubham

Vishnu

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top