Jump Statements


☞ They are also referred to as "control flow statements".

☞ They allow you to alter the flow of control in your program, determining which statements are executed and when.

☞ These are of three types :

1. break Statement
2. continue Statement
3. pass Statement

break Statement :

  • It is used to exit a loop prematurely.
  • When encountered within a loop, it causes the loop to terminate immediately, skipping the rest of the code block.
Example :
 
for i in range(1,10):
    if i==5:
        break
    print(i)
Output :
 
1
2
3
4

continue Statement :

  • It is used to skip the rest of the code block within a loop for the current iteration, and continue with the next iteration of the loop.
Example :
 
for i in range(1,10):
    if i==5:
        continue
    print(i)
Output :
 
1
2
3
4
6
7
8
9

pass Statement :

  • It is used when a statement is required syntactically but you do not want any code to execute.
Example :
 
x = int(input("Enter a number : "))
if x <= 0:
    pass  
else:
    print("Positive number")
Output :
 
Enter a number : -5
#No output for negative and 0