Given variables a, b, c, d, e, f and g of type integer.
Which of the following expressions are equal to:
if (a < b) and (c < d) then
e := f
else
e := g;
Only in case a is less than b AND c is less than d, and only then, e takes the value of f. Otherwise e takes the value of g.
[A]
e := f;
if not (a < b) then
e := g;
if not (c < d) then
e := g;
This can be changed to...
if not (a < b) or not (c < d) then
e := g
else
e := f;
...or...
if (a >= b) or (c >= d) then
e := g
else
e := f;
...which is option [B].
f is assigned to e only in case a < b and c < d. Otherwise e gets the value of g.
Therefore equal to the given term.
e := g;
if a < b then
e := f;
if c < d then
e := f;
if a < b then
if c < d then
e := f
else
e := g;
e := g;
if not (a >= b) then
e := f;
if c < d then
e := f;
[B]
if (a >= b) or (c >= d) then
e := g
else
e := f;
See option [A].
[C]
Not equal. f is assigned to e in case a is less than b OR c is less than d.
if (a < b) or (c < d) then
e := f
else
e := g;
[D]
Not equal. What value is assigned to e in case a >= b?
[E]
Not equal.
if not (a >= b) can be changed to if a < b.
e := g;
if a < b then
e := f;
if c < d then
e := f;
Same as option [C].
Keine Kommentare:
Kommentar veröffentlichen