Flow of Control
Empty statement = pass.
Simple statement = any single executable statement.
Compound statement = represents a group of statement as a unit .
Header line - starts with a keyword and ends with a colon.
Body - all the statements in the body at the same level of
indentation.
Python normally uses 4 spaces to move to next level of
indentation.
Sequence =
The sequence construct means the statements are being executed
sequentially.
The normal flow of control in a program and is the simplest one.
Selection =
The selection construct means the execution of statement (s)
depending upon a condition-test.
Selection construct is also called decision construct because it
helps in making decision about which set-of-statement is to be
executed.
Repetition Iteration (Looping) =
The iteration constructs mean repetition of a set-of-statement
depending condition-test.
The iteration is also construct called looping construct.
If statement =
if ch == ‘’ :
Statement
[ Statements ]
If - Else statement =
if <conditional expression> :
statement
[ statements ]
else :
statement
[ statements ]
If - Elif statement =
if <conditional expression> :
if <conditional expression> :
statement
statement
[ statements ]
[ statements ]
elif :
elif :
statement
statement
[ statements ]
[ statements ]
else :
statement
[ statements ]
Nested - If Statement =
Form 1 ( if inside if's body) Form 2 ( if inside elif's body)
if <conditional expression> : if <conditional expression> :
if <conditional expression> : statement(s)
statement(s) [statements]
else : elif <conditional expression> :
statement(s) if <conditional expression> :
elif <conditional expression> : statement
statement [statements]
[statements] else :
else: statement(s)
statement else:
[statements] statement
[statements]
Form 3 ( if inside else’s body) Form 4 ( if inside if's as well as
if <conditional expression> : else's or elif's body, i.e., multiple
statement(s) ifs inside)
[statements] if <conditional expression> :
elif <conditional expression> : if <conditional expression> :
statement statement(s)
[statements] else:
else : statement
if <conditional expression> : elif <conditional expression> :
statement(s) if <conditional expression> :
else: statement
statement(s) else :
statement(s)
else :
if <conditional expression> :
statement(s)
else:
statement(s)
Storing conditions =
Sometimes the conditions being used in a code are complex and
repetitive.In such cases to make your program more readable, you
can use named conditions where you can store conditions in a name
and then use that named conditional in the if statements.
Range = (starting value, ending value {required value -1 },step value)
Iteration statements are also known as looping statements.
If the condition is test before executing the loop-body, i.e., before
entering in the loop, the loop is called entry-controlled loop or pre-
condition loop.
If the condition is tested after executing the loop-body at least
once, it is called exit-controlled loop or post-condition loop.
For loop =
for <variable> in < sequence> :
statements_to repeat
While loop =
while < logical expression> :
loop-body
Break statement =
The break statement enables a program to skip over a part of the
code.
The break statement terminates the very loop it lies within.