➢ Flow Control Statements / Control Structures in Python:
The purpose of flow control statements is that to perform a certain operation only once (in case
of True perform x-operation and in case of False perform y-operation) or perform certain
operation repeatedly finite number of times until test condition becomes false.
In python, flow control statements are classified into:
a. Conditional or Selection or Branching Statements.
b. Looping or Iterative or Repetitive Statements.
c. Transfer Flow Statements.
➢ Conditional or Selection or Branching Statements:
The purpose of Conditional or Selection or Branching Statements is that to perform x-operation
in case of True and y-operation in the case of False only ONCE.
In python, we have 4 types of Conditional Statements:
a. Simple if Statement:
Syntax: The colon is called indentation symbol. All the statements combined are called
indentation block of statements or indentation suite. If we give unnecessary spaces in a
program we get the indenetation-error.
if ( Test Condition ) :
statement-1
statement-2
statement-3
---------------
---------------
statement-n
(Other Statements in Program)
Pass is the keyboard which is used to bypass the indentation block. PVM will not consider
now the indentation block.
b. if..else Statement:
Syntax:
if (test condition):
Block Statement-1
Else:
Block Statement-2
Other Statements in Program
c. if..elif..else Statement:
d. match case statement (Python 3.10 Version Onwards—PEP(Python Enhancement Proposal)):
match case is one of the conditional statement whose purpose is that to deal with pre-
designed conditions or menu-driven applications.
Syntax:
Match(Choice Expr)
Case Label-1:
Block Statements-1
Case Label-2:
Block Statements-2
Case Label-3:
Block Statements-3
------------------------------------
-----------------------------------
Case Label-n:
Block Statements-n
Case : # Default Case Block
Default Block Statement
Other Statements in Program
➢ Looping OR Iterative OR Repetitive Statements:
The purpose of looping statements is that to perform certain operations for a finite number of
times until the test condition becomes false.
At the time of solving any problem using loop, we must ensure 3 important points:
a. Initialization Part → Makes us understand from where to start.
b. Test Condition → Makes us understand where to stop – Condition becomes false.
c. Updating Part → Makes us understand to move forward or backward.
In python, we have 2 types of looping statements:
a. while loop OR while..else loop
Syntax:
while(Test Condition):
statement-1
statement-2
statement-3
---------------
statement-n
else: # Optional
statements
Other Statements in Program
If we don’t define the initialization part, we get Name Error.
If we don’t define updating part, it will work infinite amount of time.
b. for loop OR for..else loop
Syntax1:
for var_name in iterable_object:
--------------------------
Block of Statements
--------------------------
Other Statements
Syntax2:
for var_name in iterable_object:
-----------------------------
Block of Statements-1
-----------------------------
else:
-----------------------------
Block of Statements-2
-----------------------------