Break,Continue and Pass in Python

  Looping control statements or Unconditional control statement in Python:

  • Unconditional control statement is also called a jump statement.
  • There are three kinds of jumping statements,

*Break

*Continue

*Pass

Break statement:

  • The break statement is used to execute particular blocks only.
  • If give break statement then it stops the process.

Syntax:

  1. Loop or if conditions:

             break

Example program:

  1. #Write a program to check pin number until it becomes correct

    pin=1234

    while True:

        p=int(input("Enter pin number: "))

        if(p==pin):

            print("you can choose the below options: \n1.Cash withdrawal \n2.Cash deposit \n3.Mini Statement")

            break

        else:

            print("Sorry try again!!!")

Output:

if-condition with break:

else-condition:

Continue statement:

  • The continue statement is used inside loops.
  • Whenever a continue statement is encountered inside a loop, control directly jumps to the beginning of the loop for the next iteration, skipping the execution of statements inside the loop’s body for the current iteration.
  • The continue is a special statement which is used within to force the next iteration to happen.

  • It is syntactically allowed to appear only within a for or while loop.

Syntax:

  1. Loop or if conditions:

             continue

Example program:

  1. for i in range(10):

        if i%2 == 0:

            continue

        print(i,end=" ")

Output:

Pass statement:

  • It is a null operation or default statement.
  • It is typically used when an empty need function is required that time use the pass statement.
  • It basically the pass statement give or not, working as normal. i.e, with pass and without pass are the same.

Syntax:

  1. Loop or if conditions:

             pass

Example program:

  1. for i in range(1,11):

        pass

        print(i,end=" ")

Output:

Share:

No comments:

Post a Comment

Popular Posts

Search This Blog

Powered by Blogger.

Service Support

Need our help to Learn or Post New Concepts Contact me

Recent Posts

Service Support

Need our help to Learn or Post New Concepts Contact me