basic.case

Statement/BASIC Program, Releases: AP and R83

Initiates the case statement.

Syntax

begin case case logical.expression {statement{s}} . case logical.expression {statement{s}} . . end case

Description

delineates a conditional case construct.

Only the statements following the first 'true' case statement are executed. Upon completion of these statements program execution continues immediately following the 'end case' statement.

If all 'case' statements evaluate false, program execution is continued at the first statement after the 'end case'.

A 'case 1' statement always evaluates true and is used as the last case statement to be processed only when all previous case statements evaluate to false.

The 'case' statement is equivalent to nested 'if' expressions as follows:

if logical.expression then
{statement{s}}
end else
if logical.expression then
{statement{s}}
end
end

The statements between 'case' statements are executed if the expression associated with the case evaluates to true. If the expression evaluates to false, the statements are not executed.

Example

begin case
* check for operators response
case response = 'p'
printer on
case response = 's'
echo off
case 1
crt 'response must be 'p' or 's''
end case

In this example, if the response is 'p', the 'printer on'
statement is issued. The program would then branch to the next statement after
'end case'. The 'case 1' is executed only if response is
neither 'p' nor 's'.

See Also

Command Name Type Description
basic.statements Definition Definition of statements and functions.
basic.end.case Statement Terminates case construct.
basic.if Statement Initiates logical expression.
basic.match Relational Operator Pattern matching function.
basic.logical.expressions Definition application of logical (Boolean) operators to relational or arithmetic expressions.
basic.begin.case Statement
branching Definition

User Comments

What do you think?

Share your experience or ask a question by using the form below.

Login to leave your comments.