0% found this document useful (0 votes)
56 views2 pages

Conditional Flow Control Defination With Syntax

Uploaded by

Land lord
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views2 pages

Conditional Flow Control Defination With Syntax

Uploaded by

Land lord
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

""

flow control statements:


"""
"""
*controlling the flow of program execution is called as flow control statements.
*flow control stmt is classified into 2 types,
1.conditional flow control stmt
2.loop flow control stmt

1.conditional flow control stmt:


********************************
*controlling a flow of program execution basedon condition is called as conditional
flow control stmt.
*conditional stmt is classified into 4 types,
1.simple if
2.if-else
3.elif
4.nested if-else

1.simple if:
************
*if cond become True "if block/TSB" will get execute else it will just go with flow
of program execution.

syntax:
*******
if cond:
stmt1 }
stmt2 }---> TSB/if block
stmt3 }
stmt4
stmt5
stmt5
:

"""
drawback of simple-if:
**********************
*if cond is False we dont have any specific block of code to execute, to over this
we go "if-else"
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------
2. if-else:
***********
*if cond become "True" "if block/TSB" will get execute else if cond become "False"
"else block/FSB" will execute.

syntax:
*******
if cond:
stmt1 }
stmt2 }---> TSB/if block
stmt3 }
else:
stmt4 }
stmt5 }---> FSB/else block
stmt6 }
"""
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------
3.elif:
*******
*when ever we want to check multiple conditions then we go elif.
*if cond1 is True it will ignore other all cond's and execute TSB1, else if cond1
is False then it will check cond2.
*if cond2 is True then it will ignore other cond's and execute TSB2, else if cond2
is False then it will check for other cond's present.
*if all cond's are False then it will execute FSB/else-block.

syntax:
-------
if cond1:
stmt1 }-->if block1/TSB1
elif cond2:
stmt2 }-->if block2/TSB2
elif cond3:
stmt3 }-->if block3/TSB3
else:
stmt4 }-->else block/FSB

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------
nested if-else:
***************
*when if-else present inside another if-else stmt is called as nested if-else stmt.
*if outer if(cond1) become True then inner if-else cond will get execute, else
outer if(cond1) is False then outer else(stmt3) will get execute.
*if inner if(cond1) become True then TSB(stmt1) will get execute other wise inner
else block/FSB(stmt2) will get execute.

syntax:
-------
if cond1: #outer if-else stmt
if cond2: #inner if-else stmt
stmt1
else:
stmt2
else:
stmt3

You might also like