Jump Statement in Python programming | Hands on coding

  • Jump Statement is used to transfer the control from one point to another point in the program.

break statement:

  • break statement 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 n in range(1,11):
    print(n,end=" ")
/*
1 2 3 4 5 6 7 8 9 10 
*/

for n in range(1,11):
    if n==5:
        break
    else:
        print(n,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 n in range(1,11):
    if n==5:
        continue
    else:
        print(n,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 n in range(1,11):
    if n>=5:
        continue
    else:
        print(n,end=" ")
/*
1 2 3 4 
because condition of  if  will remain
true when  n will be either 5 or 
greater than 5
*/

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