Let us express the pre and post conditions of each statement.
In this case, let us not to assume any values in the variables.
In other words,
The pre condition of line 2 is not just
.
This is because the only way that we get to line 2
is that the condition
must be true. Consequently,
. Using the same argument, the only
way we get to line 4 is that
, which
is equivalent to saying
. As a result,
.
The post condition of line 2 is simply
. Similarly,
the post condition of line 4 is
.
Here comes the trickly part: what is
? In
other words, after the entire conditional statement, what can we conclude?
There are two ways to get to line 5. We can get there from line 2, or from line 4. Consequently, the post condition of line 5 is the post condition of line 2 or the post condition of line 4. In other words,
![]() |
![]() |
![]() |
(15) |
![]() |
![]() |
(16) |
Does this make sense?
Here is the general conditional statement:
Copyright © 2012-02-07 by Tak Auyeung