<SPAN CLASS="TOKEN" >case</SPAN > statements

Sather - Language Specification
Prev | Chapter 5. Basic Statements | Next

# 5.5. case statements

Example 5-5. Example:

    case i
    when 5, 6 then ...
    when j then ...
    else ...
    end

    case_statement ==>
            case expression when expression { ,  expression }  then  statement_list { when expression { ,  expression }  then  statement_list } [ else statement_list ] end

Multi-way branches are implemented by case statements. There may be an arbitrary number of when clauses and an optional else clause. The initial expression construct is evaluated first and may have a return value of any type. This type must define one or more routines named 'is_eq' with a single argument and a boolean return value. The case statement is semantically syntactic sugar for (equivalent to) an if statement, each of whose branches tests a call of is_eq. The arguments to these calls are the expressions of successive when lists. The first one of these calls to returns true causes the corresponding statement list to be executed and control passed to the statement following the case statement. If none of the when expressions matches and an else clause is present, then the statement list following it is executed. It is a fatal error if no branch matches in the absence of an else clause.

Prev | Home | Next
return statements | Up | typecase statements