- Python transfer statement transfers the execution of the statement to another statement.
- It is also known as transfer statements.
- What is Control statement?
Managing the flow of program execution.
- Transfer statement transfers the flow of execution from the current statement to a specific statement.
- Types of Control statement in python: break statement, continue and pass
- The following diagrams show a list of control statements in python
- What is a break statement
break statement in python: Breaking the execution of a loop or come out of the loop.
- We use break statement where we want to break the loop execution based on some conditions.
- Break Syntax
To break loop we simply write break
- Break Flowchart
- Break statement example
Break statement examplePython1234567print("Break statement example")for I in range(10):if I ==3:print("Stop the loop using break")breakprint(I)print("Program End")
- Continue with the next iteration by skipping rest, statements.
- Continue in python: Skips the current iteration and go for the new iteration.
- Continue Flow chart
- Python continue statement Example
Read only odd numbers from 1 to 10
continue statement examplePython123456print("continue statement example")for i in range(10):if i%2==0:continueprint(i)print("Program End")
- It is an empty statement.
- It is a null statement.
- pass statement won’t do anything.
- Pass statement in python: If you don’t want to do anything then go for pass statement.
Suppose you written a function
But in some situations, you don’t want to define a function.
Def f1(): doing this much only gives a error that you have to define a function.
So, you can write a pass in this situation where you don’t want to do anything.
To define empty block you can write pass statement.
In case if inheritance in base case if you don’t want to define function then in other programming language you use abstract function and define the function in a child class.
You can implement such a scenario in python using pass statement.
- Pass example
print even numbers and pass if a number is odd
Pass statement examplePython12345678print("Pass statement example")for I in range(10):if(I%2==0):print(I)else:print("pass")passprint("Program End")
- Pass statement mostly used in object oriented concept.