Professional Documents
Culture Documents
2 Branches Slides
2 Branches Slides
p
Software Development 1
Decisions
Overview
Introduction
Basic
B i decision
d i i making ki – if statement
t t t
Evaluating expressions
Mutually exclusive execution
Multiple parallel branches
Multiple values versus multiple conditions
Summary
Introduction
Computer programs perform millions of
calculations
l l ti per second.
d
The
Th also
l take
t k millions
illi off d
decisions
i i per second.
d
Th
The if,
if else,
l and
d elif
lif statements
t t t provide
id this
thi
capability
Basic decision making
The if statement
provides
id ththe means
to conditionally
executet a sequence
of statement
Condition
C diti iis a
boolean expression
Generally in the form
of a comparison
if syntax
# common branch
statement5
statement6
Multiple branches
Nested if statements
used
d
if within an if
if within else
Functionally equivalent
Multiple values
Multiple variables
Multiple values
Both conditions operate on a common variable
off interest
i t t
if x > 0:
x>0 # execute branch 1
else
l :
x<0 if x < 0:
# execute branch 2
x == 0 else:
# execute branch 3