6.7. Omitting the
else Clause: Unary Selection¶
Another form of the
if statement is one in which the
else clause is omitted entirely. This creates what
is sometimes called unary selection. In this case, when the condition evaluates to
True, the statements
are executed. Otherwise the flow of execution continues to the statement after the body of the
Below is a flowchart of an if without an else clause:
Predict the output for the code below and then run it.
What would be printed if the value of
x is negative in the example above? Try it.
Check your understanding