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 :
otherwise:
x :
In the above code, since the Boolean expression true evaluates to the value true, the first bit of code is executed, namely x : As such, when this code completes, program variable x will hold the value
Conversely, consider the following variant of the above code:
if false then:
x :
otherwise:
x :
In the above case, since the Boolean expression false evaluates to the value false, the bit of code underneath otherwise is executed, namely x : As such, program variable x ends up holding the value
The following code illustrates a more complex example:
if then:
x :
otherwise:
x :
In the above case, since the Boolean expression evaluates to true, the first bit of code is executed, namely x : As such, when this code completes, program variable x will hold the value
Consider the following code:
if then:
x :
otherwise:
x :
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
