Question: if checks a condition, which is an expression of type Boolean. This condition is given in parentheses ( ( ) ) . If the condition

if checks a condition, which is an expression of type Boolean. This condition is given in parentheses (()). If the condition evaluates to true, then the first bit of given code is executed. Conversely, if the condition evaluates to false, then the second bit of given code is executed. For example, consider the following code:
if (true) then:
x :=8
otherwise:
x :=9
In the above code, since the Boolean expression true evaluates to the value true, the first bit of code is executed, namely x :=8. As such, when this code completes, program variable x will hold the value 8.
Conversely, consider the following variant of the above code:
if (false) then:
x :=8
otherwise:
x :=9
In the above case, since the Boolean expression false evaluates to the value false, the bit of code underneath otherwise is executed, namely x :=9. As such, program variable x ends up holding the value 9.
The following code illustrates a more complex example:
if (1<2) then:
x :=8
otherwise:
x :=9
In the above case, since the Boolean expression 1<2 evaluates to true, the first bit of code is executed, namely x :=8. As such, when this code completes, program variable x will hold the value 8.
Consider the following code:
if (1<0) then:
x :=1+1
otherwise:
x :=2+2
What value does program variable x hold when the above code completes?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!