Jump Statement in Python

Hello friends how are you, today in this blog i will teach you what is jump statement, types of Jump Statement , how Jump Statement works and many programs using Jump Statement in a very simple way. 

Let's start
  • It is used to transfer the control from one point to another point in the program.

break statement

  • It is used to transfer the control out of the body of loop.
  • In other word we can say that it terminates the current loop.
  • break statement are mostly used with loop(for loop or while loop).

for i in range(1,11):
    print(i,end=" ")
/*
1 2 3 4 5 6 7 8 9 10 
*/

for i in range(1,11):
    if i==5:
        break
    else:
        print(i,end=" ")
/*
1 2 3 4 
*/
 

continue statement

  • It is used to skip the next statement and continue the loop.
  • continue statement are mostly used with loop(for,while).

for i in range(1,11):
    if i==5:
        continue
    else:
        print(i,end=" ")
/*
1 2 3 4 6 7 8 9 10 
5 will not print because at this
time condition  will become true
and loop will continue printing
*/

for i in range(1,11):
    if i>=5:
        continue
    else:
        print(i,end=" ")
/*
1 2 3 4 
because condition of  if  will remain
true when anil will be either 5 or 
greater than 5
*/

for i in range(1,11):
    if i<=5:
        continue
    else:
        print(i,end=" ")
/*
6 7 8 9 10 
because condition of if is true 
whene value of i is either 5
or less than 5
*/

for i in range(1,11):
    if i!=5:
        continue
    else:
        print(i,end=" ")
/*
5
because else part will 
execute if and only if the
value of i is 5  
*/
 

Request:-If you found this post helpful then let me know by your comment and share it with your friend. 

If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all. 

If you have not subscribed my website then please subscribe my website. 

Try to learn something new and teach something new to other. Thanks.

Post a Comment

0 Comments