swirl
Guide to OmniMark 9   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
     
control structure  

do select, case

 
 

Syntax

do select numeric-expression
(case selector (| selector)*
     local-declaration*
     action*)+
( else
    local declaration*
    action*)?
done


Purpose

Evaluates a numeric expression, compares it against the numeric values or ranges in the case alternatives, then selects the alternative that applies. It is an error to have more than one case alternative apply to the same value.

If none of the case alternatives apply, and there is an else declaration, then the else declaration is selected. Otherwise, none of the parts are selected.

If a part was selected, the actions in that part are performed. Otherwise, none of the actions are performed.

The numeric ranges are inclusive. If the value falls between the upper and lower bounds, or matches either bound, the test succeeds and that case alternative is selected.

It is an error for a selecting value to match more than one case alternative. Each range set in a do select must describe a set of values separate from those in all the other range sets. This provision provides error detection, avoids "what happens when" questions, and allows for optimization.

This code sample shows how do select is used to evaluate a numeric expression, and then compare that expression against the numeric values or ranges in the case alternative, in order to select the alternative that applies.

If none of the case alternatives apply and there is an else part, then the else is selected.

  local integer val
  ...
  do select val
  case 1 | 3 | 5
    ; do something
  case 2 | 4 | 6 to 10
    ; do something else
  else
    ; do something different
  done

       
 

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ LEGACY LIBRARIES ] [ ERRORS ]

OmniMark 9.1.0 Documentation Generated: September 2, 2010 at 1:51:21 pm
If you have any comments about this section of the documentation, please use this form.

Copyright © Stilo International plc, 1988-2010.