15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

582<br />

Branching Statements<br />

One problem with the IF-THEN statement is that it only gives you two possible<br />

choices. To offer multiple choices, Pascal also uses the CASE statement,<br />

such as<br />

CASE variable OF<br />

value1: BEGIN<br />

Commands;<br />

END;<br />

value2: BEGIN<br />

Commands;<br />

END;<br />

END;<br />

The preceding CASE statement is equivalent to the following IF-THEN-ELSE<br />

statement:<br />

IF variable = value1 THEN<br />

BEGIN<br />

Command<br />

END;<br />

ELSE<br />

IF variable = value2 THEN<br />

BEGIN<br />

Commands;<br />

END;<br />

END;<br />

To check if a variable matches multiple values, you can separate multiple<br />

values with commas or you can match a range of values, such as<br />

CASE variable OF<br />

value1: BEGIN<br />

Commands;<br />

END;<br />

Value2..value4: BEGIN<br />

Commands;<br />

END;<br />

END;<br />

The preceding CASE statement is equivalent to the following IF-<br />

THEN-ELSEIF statement:<br />

IF variable = value1 THEN<br />

BEGIN<br />

Commands;<br />

END<br />

ELSE IF (variable >= value2) AND (variable

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!