Control Stuctures
Control Stuctures
2. SELECTION
3. ITERATION OR LOOPING
4. BRANCHING OR JUMPING
STATEMENTS
Decision Making / selection
Decision Making
• Decision structures evaluate multiple expressions which
produce TRUE or FALSE as outcome.
• Needs to determine which action to take and which
statements to execute if outcome is TRUE or FALSE
otherwise.
• TRUE
• any non-zero and non-null values
• FALSE
• either zero or null
Typical decision making structure
Decision Making
Flow graph
Condition
Conditional
Code
Types of decision making statements.
Decision Making
Flow graph
Types of Decision
making systems
Python IF Statement
Decision Making • The if statement contains a logical expression using which
Flow graph data is compared and a decision is made based on the
Types of Decision result of the comparison.
making systems
IF Statement
• Syntax
Syntax if expression:
statement(s)
• Flow Diagram
Flow Diagram
Decision Making
Flow graph
Types of Decision
If the condition is
making systems true
IF Statement Condition
Syntax
Flow graph
If the condition is
FALSE
Conditional
Code
Example
Decision Making var1 = 100
Flow graph
if var1:
Types of Decision
making systems print ("1 - Got a true expression value")
IF Statement print (var1)
Syntax
Flow graph
Example
var2 = 0
if var2:
print ("2 - Got a true expression value")
print (var2)
print ("Good bye!")
Python IF... ELSE Statements
Decision Making • An else statement can be combined with an if statement.
Flow graph
• An else statement contains the block of code that executes
Types of Decision
making systems
if the conditional expression in the if statement resolves to
IF Statement
0 or a FALSE value.
Syntax • Syntax
Flow graph
IF-ELSE statement
if expression:
Syntax statement(s)
else:
statement(s)
Flow Diagram
Decision Making
Flow graph
Types of Decision
If the condition is
making systems true
IF Statement Condition
Syntax
Flow graph
If the condition is
IF-ELSE statement FALSE
Syntax
Flow graph
FALSE Conditional TRUE Conditional
Code Code
Example
Decision Making var1 = 100
Flow graph
if var1:
Types of Decision
making systems print ("1 - Got a true expression value")
IF Statement print (var1)
Syntax
Flow graph else:
IF-ELSE statement print ("1 - Got a false expression value")
Syntax
Flow graph print (var1)
Example
Example
Decision Making var2 = 0
Flow graph
if var2:
Types of Decision
making systems print ("2 - Got a true expression value")
IF Statement print (var2)
Syntax
Flow graph else:
IF-ELSE statement print ("2 - Got a false expression value")
Syntax
Flow graph print (var2)
Example