Introduction
As we now all know how to declare a variable in Python, the different Tokens of Python as well as its Datatypes. Now, we will use them in some conditional statements and see how Python Programs are implemented with flowcharts and examples.
What are the Flow Control Statements?
A Flow Control Statement defines the flow of the execution of the Program.
There are 6 different types of flow control statements available in Python:
- if-else
- Nested if-else
- for
- while
- break
- Continue
Let’s learn about these all statements in detail.
if-else
If-else is used for decision making; when code statements satisfy the condition, then it will return non-zero values as true, or else zero or NONE value as false, by the Python interpreter.
Syntax
- if(<condition>):
- Statement 1
- ...
- else:
- Statement 2
- ...
Understand this statement with a flow chart.
Example
Check In[3] and In[4] and also In[5] and In[6].
Nested if-else
With if...elif...else, elif is a shortened form of else if. It works the same as 'if' statements, where the if block condition is false then it checks to elif blocks. If all blocks are false, then it executes an else statement. There are multiple elif blocks possible for a Nested if...else.
Syntax
- if (<condition 1>):
- Statement 1
- ...
- elif (<condition 2>):
- Statement 2
- ...
- else
- Statement 3
- ...
Flow chart of Nested-if else
Remember there is no condition statement associated with else part of these flow control statements. It will execute ig statements only in the case that of all conditions are false.
Example
Check In[3] and In[8] and also In[9] and In[10].
for Statement
The for loop statement has variable iteration in a sequence(list, tuple or string) and executes statements until the loop does not reach the false condition.
Syntax
- for value in sequence:
- ...body statement of for
Flow chart of for statement
Example
Check In[14] and In[16]. The continue statement is used to stop for loop, in case there is an else block missed.
while loop
A while loop is used in python to iterate over the block of expression which matches to true. Non-zero values are True and zero and negative values are False, as interpreted in Python.
Syntax


Koshila SenadhiraPosted Dec 1, 2022, 11:18 AM
Interesting Article!
Sourav Kumar DasPosted Dec 6, 2019, 6:28 AM
Nice clearly explained mam.
Onkar SharmaPosted Dec 6, 2019, 6:19 AM
Very Informative article...