Conditional Statements
Conditional Statements
Computer programs need to make decisions.
We use a conditional statement in programming to test
whether or not something is true.
A conditional statement takes the form IF…THEN…
IF something is true THEN do something
Pseudocode
Python
Pseudocode
Python
Else
The ELSE statement can be used with the IF statement to
provide an alternative outcome from the condition.
The conditional statement can be extended to take the
form IF…THEN…ELSE
IF something is true THEN
do something
ELSE
do something different
Pseudocode
Python
Multiple Conditions
It is possible to further extend the conditional statement to
test for more than one condition.
IF something is true THEN
do something
ELSE IF something else is true
do something different
ELSE IF something else again is true
do something different
etc
Pseudocode
Python
Comparison Operators
So far we have tested to see if two things are equal, but
there are other comparison operators we can use.
Operator Description
= (note: == in Python) Equal to
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
<> (note: != in Python) Not equal to
Pseudocode

SDD Conditional Statements

  • 1.
  • 2.
    Conditional Statements Computer programsneed to make decisions. We use a conditional statement in programming to test whether or not something is true. A conditional statement takes the form IF…THEN… IF something is true THEN do something
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
    Else The ELSE statementcan be used with the IF statement to provide an alternative outcome from the condition. The conditional statement can be extended to take the form IF…THEN…ELSE IF something is true THEN do something ELSE do something different
  • 8.
  • 9.
  • 10.
    Multiple Conditions It ispossible to further extend the conditional statement to test for more than one condition. IF something is true THEN do something ELSE IF something else is true do something different ELSE IF something else again is true do something different etc
  • 11.
  • 12.
  • 13.
    Comparison Operators So farwe have tested to see if two things are equal, but there are other comparison operators we can use. Operator Description = (note: == in Python) Equal to < Less than > Greater than <= Less than or equal to >= Greater than or equal to <> (note: != in Python) Not equal to
  • 14.