Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

if can be chained along to check multiple conditions. The first condition which evaluates to true ends up being the one picked. If none of

if can be chained along to check multiple conditions. The first condition which evaluates to true ends up being the one picked. If none of the conditions evaluate to true, then the code in the final otherwise is executed. For example, consider the following code:
if (1>10) then:
x :=0
otherwise if (10>2) then:
x :=1
otherwise:
x :=2
In this case, since 1>10 evaluates to false, the first bit of code is skipped. The condition 10>2 is then evaluated, producing true. Since this condition evaluates to true, the code underneath this specific condition is executed. This places value 1 into variable x. At this point, there is nothing left to exeucte.
Consider the following code:
if (2>2) then:
x :=0
otherwise if (2>4) then:
x :=1
otherwise if (2>=5) then:
x :=2
otherwise:
x :=3
What value does program variable x hold when this code is finished executing?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions