SWITCH

Purpose:

Transfers control to one of several statements depending on the value of an expression.

Syntax:

switch (expr) statements

expr

-

Any expression resolving to a number or string.

statements

-

One or more valid expressions separated by semicolons.

Returns:

The result of evaluating statements.

Example:

test(x)
{
    local a;
 
    switch (x)
    {
        case 10:
        case 22.5:
            a = 1;
            break;
 
        case "text":
            a = 2;
            break;
 
        default:
            a = 0;
            break;
    }
 
    return(a);
}

 

test(10) == 1

test("text") == 2

test(3) == 0

Remarks:

Unlike C/C++, expression may evaluate to an integer, real or string value. The statement is typically compound and is labeled with a case prefix as follows:

 

case constant-expression:

 

Each case constant must be unique. The optional default labeled statement is executed if expression does not compare to any case constant.

See Also:

BREAK

IF

SPL: Series Processing Language

WHILE