Progress
Language Reference


CASE Statement

Interfaces
OS
SpeedScript
All
All
Yes

Provides a multi-branch decision based on the value of a single expression.

SYNTAX

CASE expression :
  {  WHEN value [ OR WHEN value ] ... THEN
       { block | statement }
  } ...
  [  OTHERWISE
       { block | statement }
  ]
END [ CASE ] 

expression

The expression that determines which branch of code to execute. The expression parameter can be any valid Progress expression. It can include comparisons, logical operations, and parentheses.

WHEN value [ OR WHEN value ] . . . THEN

Each value is an expression that evaluates to a possible value for expression. If value matches the current value of expression, then the associated block or statement executes.

OTHERWISE

Introduces a block or statement to execute when the value of expression does not match any value in any of the WHEN clauses.

block

A DO, FOR EACH, or REPEAT block. If you do not use a block, then you can only use a single statement for the WHEN or OTHERWISE clause.

statement

A single 4GL statement. If you want to use more than one statement, you must enclose them in a DO, FOR EACH, or REPEAT block.

END [ CASE ]

Indicates the end of the CASE statement. You can include the CASE keyword here to improve readability; it has no effect on the code.

EXAMPLE

The following fragment shows a simple example of a CASE statement.

r-case.p
DEFINE VARIABLE pay-stat    AS INTEGER INITIAL 1.

UPDATE pay-stat VIEW-AS RADIO-SET
  RADIO-ITEM unpaid   1 LABEL "Unpaid"
  RADIO-ITEM part     2 LABEL "Partially paid"
  RADIO-ITEM paid     3 LABEL "Paid in full".

CASE pay-stat:
  WHEN 1 THEN
    MESSAGE "This account is unpaid.".
  WHEN 2 THEN  
    MESSAGE "This account is partially paid.".
  WHEN 3 THEN  
    MESSAGE "This account is paid in full.".
END CASE. 

NOTES


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095