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.

598<br />

Branching Statements<br />

To make the computer choose between two mutually exclusive sets of commands,<br />

you can use an IF-THEN-ELSE statement, such as<br />

IF condition THEN<br />

Command<br />

ELSE<br />

Command<br />

END IF<br />

If a Boolean condition is True, the IF-THEN-ELSE statement runs the<br />

first group of commands, but if the Boolean condition is False, the<br />

IF-THEN-ELSE statement runs the second group of commands. An IF-<br />

THEN-ELSE statement will always run one set of commands or the other.<br />

A variation of this is the IF-THEN-ELSEIF statement, which uses two or<br />

more Boolean conditions to choose which of two or more groups of commands<br />

to run, such as<br />

IF condition1 THEN<br />

Command<br />

ELSEIF condition2 THEN<br />

Command<br />

END IF<br />

Whereas the IF-THEN-ELSE statement can only give the computer a choice<br />

of two groups of commands to run, the IF-THEN-ELSEIF statement can<br />

offer the computer two or more groups of commands to run, such as<br />

IF condition1 THEN<br />

Command<br />

ELSEIF condition2 THEN<br />

Command<br />

ELSEIF condition3 THEN<br />

Command<br />

END IF<br />

As an alternative to the IF-THEN-ELSEIF statement, you can also use the<br />

SELECT-CASE statement, such as<br />

SELECT CASE variable<br />

CASE value1<br />

Command<br />

CASE value2<br />

Command<br />

CASE value3<br />

Command<br />

END SELECT

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

Saved successfully!

Ooh no, something went wrong!