Skip to main content
AGENDA

Decision Making
Loops
Python Decision Making


Decision making structures require that the
programmer specify one or more conditions to be
evaluated or tested by the program, along with a
statement or statements to be executed if the condition is
determined to be true, and optionally, other statements to
be executed if the condition is determined to be false.
Types of decision making
statements
 IF statements
 IF...ELSE statements
 Nested IF statements
IF statements Flow Diagram:

Test Exp

FALSE

TRUE

Body of if

EXIT
IF...ELSE statements Flow Diagram:

Test Exp

FALSE

If Block

TRUE

Body of Else



EXIT
The else statement is an optional statement and there could be at most only one
else statement following if .
LOOPS




A loop statement allows us to execute a statement or
group of statements multiple times
Python programming language provides following types
of loops to handle looping requirements

 While loop
 For loop
While Loop
Example:
count = 0
while (count < 9):
print 'The count is:', count
count = count + 1
print "Good bye!"
For Loop
If a sequence contains an expression list, it is
evaluated first. Then, the first item in the sequence is
assigned to the iterating variable iterating_var. Next, the
statements block is executed. Each item in the list is
assigned to iterating_var, and the statement(s) block is
executed until the entire sequence is exhausted.
Example:
for letter in 'Python':
print 'Current Letter :', letter

String
Loop Control Statements:
Loop control statements change execution from its
normal sequence. When execution leaves a scope, all
automatic objects that were created in that scope are
destroyed.


break statement



continue statement



pass statement
Break Statement:

Example
for letter in 'Python':
if letter == 'h':
break

Break Statement

print 'Current Letter :', letter
continue statement
The continue statement in Python returns the control
to the beginning of the while loop. The continue
statement rejects all the remaining statements in the
current iteration of the loop and moves the control back
to the top of the loop.
for letter in 'Python':
if letter == 'h':
continue

continue statement

print 'Current Letter :', letter
pass statement
The pass statement in Python is used when a statement
is required syntactically but you do not want any
command or code to execute.
The pass statement is a null operation; nothing happens
when it executes.
for letter in 'Python':
if letter == 'h':
pass
print 'This is pass block'
print 'Current Letter :', letter
Reference


http://www.tutorialspoint.com/python/
Python session3