Open In App

Jump Statements in Python

In any programming language, a command written by the programmer for the computer to act is known as a statement. In simple words, a statement can be thought of as an instruction that programmers give to the computer and upon receiving them, the computer acts accordingly.

There are various types of statements in programming and one such type of statement is known as Jump Statement. So, this article contains what a jump statement is, its types, its syntax, and a few programs based on them.



Jump Statement: As the name suggests, a jump statement is used to break the normal flow of the program and jump onto a specific line of code in the program if the specific condition is true. In simple words, it transfers the execution control of the program to another statement if a specific condition associated becomes true. As we proceed further you will get a better understanding of this concept.

Types of Jump Statements:

Syntax:



Loop{
    Condition:
        break
    }

Example:




# for loop traversing from 1 to 4
for i in range(1, 5):
  # If this condition becomes true break will execute
    if(i == 3):
     # Break statement will terminate the entire loop
        break
    print(i)

Output
1
2

Syntax:

while True:
    ...
    if x == 100:
        continue
    print(x)

Example:




# for loop traversing from 1 to 4
for i in range(1, 5):
  # If this condition becomes true continue will execute
    if(i == 2):
      # Continue statement will skip the iteration when i=2 and continue the rest of the loop
        continue
    print(i)

Output
1
3
4

Syntax:

def function: 
pass

Example:




# Traversing through every character of the string
for alphabet in 'Legends':
         # If alphabet='g' program will do nothing and won't print the letter
    if(alphabet == 'g'):
        pass
    else:
        print(alphabet)

Output
L
e
e
n
d
s

Syntax:

def fun():
  statements
  .
  .
  return [expression]




# Python program to demonstrate the
# return statement
 
# Function to multiply the two numbers
# x and y
def multiply(x, y):
 
    # returning the multiplication
    # of x and y
    return x * y
 
# Driver Code
result = multiply(3, 5)
 
print(result)

Output
15

Article Tags :