Jump Statement in Python | Complete Guide with Examples

0
Jump Statement in Python | Complete Guide with Examples
Jump Statement in Python | Complete Guide with Examples

📑 Table of Contents

Jump Statement in Python Definition

Jump Statement: A jump statement in Python is used to alter the flow of control in a program. It is most important features in python language. In jump statement is not a built-in keyword. if you are referring to control flow statements that allow you to jump to different parts of your code you might be thinking of statements like break, continue, pass and return. 

Types of Jump Statement in Python

  • break: Exits the nearest enclosing loop.
  • continue: Skips the rest of the code inside the loop for the current iteration and moves to the next iteration.
  • return: Exits a function and optionally passes back a value to the caller.
  • pass: A null statement that is used as a placeholder when a statement is syntactically required but no action is needed.

Define Break Statement in Python

Break Statement: A break statement can be used to terminate the nearest enclosing loop for or while loop prematurely. When the break statement is executed, the control is transferred to the statement immediately following the loop. It is commonly used to exit a loop when a certain condition is meet.

Syntax of Break Statement in Python

for loop:
    condition:
       break
    Statements

Example of Break Statement in Python

data=["Jiocoding","Python","JavaScript","Java","C++","Ruby","Go","Swift","Kotlin","PHP"]
for name in data:
    if name == "Python":
            print("Name is found:", name)
            break
    else:
        print("Searching...", name)

============OUTPUT============
Searching... Jiocoding

Name is found: Python

Simple Example of Break Statement in Python

facebook=["Jiocoding","Ram","Shyam","Mohan","Sohan","Ramesh","Suresh","Mahesh"]
for name in facebook:
        if name == "Ramesh" or name == "Sohan":
             break
        print("Facebook User:", name)

============OUTPUT============
Facebook User: Jiocoding

Facebook User: Ram
Facebook User: Shyam
Facebook User: Mohan

Define Continue Statement in Python

Continue Statement: continue statement can be used to skip the rest of the code inside a loop for the current iteration and move to the next iteration of the loop. It is commonly used within for loop and while loop to bypass certain iterations based on a condition allowing the loop to continue with the next item or iteration without executing any remaining code in the current iteration.

Syntax of Continue Statement in Python

for loop:
    condition:
       continue
    Statements


Example of Continue Statement in Python

data=["Jiocoding","Python","JavaScript","Java","C++","Ruby","Go","Swift","PHP"]
for name in data:
        if name == "Python" or name == "JavaScript" or name == "Java":
                continue
        print("Name is found:", name)

============OUTPUT============
Name is found: Jiocoding

Name is found: C++
Name is found: Ruby
Name is found: Go
Name is found: Swift
Name is found: PHP

Simple Example of Continue Statement in Python

data=["Jiocoding", "C", "C++","Java")
for name in data:
        if name=="C":
            continue
        print("Your List Data:",name)

============OUTPUT============
Your List Data:Jiocoding
Your List Data:C++
Your List Data:Java

Return Statement Definition in Python

Return Statement: return statement can be used to exit a function and optionally pass back a value to the caller. If no value is specified after the return keyword the function will return None by default. It can be mostly used by python functions.

Syntax of Return Statement in Python

def function_name():
        function body
        return value

Return Statement in Python Example

x=int(input("Enter first number: "))
y=int(input("Enter second number: "))
def Calculation():
            res=x*y
            return res
result=Calculation()
print("The multiplication of two numbers is:",result)

============OUTPUT============
Enter first number: 7
Enter second number:8
The multiplication of two numbers is: 56


By Default Return None Statement in Python Example

def Addition(x,y):
        return x+y
def Subtraction(x,y):
        pass
x=int(input("Enter first number: "))
y=int(input("Enter second number: "))
print("Addition:",Addition(x,y))
print("Subtraction:",Subtraction(x,y))

============OUTPUT============
Enter first number: 7
Enter second number:8
Addition: 12
Subtraction: None

Define Pass Statement in Python

Pass Statement: pass statement can be used is a null operation. it is used when a statement is syntactically required but you do not want to execute any code. It serves as a placeholder in situations where code will eventually be added. but you can now want to maintain the structure of your code without causing any errors.

Syntax of Pass Statement in Python

def function_name1():
           pass
def function_name2():
            pass
def function_name3():
            pass
def function_name4():
            pass

Example of Pass Statement in Python

def Addition(x,y):
           pass
def Subtraction(x,y):
            pass
def Multiplication(x,y):
            pass
def Division(x,y):
            pass

x=int(input("Enter first number: "))

y=int(input("Enter second number: "))
print("Addition:",Addition(x,y))
print("Subtraction:",Subtraction(x,y))
print("Multiplication:",Multiplication(x,y))
print("Division:",Division(x,y))

============OUTPUT============
Enter first number: 6

Enter second number: 8
Subtraction: None
Multiplication: None
Division: None

Conclusion of Jump Statement in Python

Conclusion: This is a all about python jump Statements. It is a most important features of python. I can explain every jump statements in this article If your any query for in this article than you can contact me by email i can provide best solutions.

Post a Comment

0 Comments
Post a Comment (0)
To Top