CASE |
"case" is used to provide an alternative control structure, according to the value of a given expression.
Caseexpr_choix
{ When expr_v { , expr_v } [ : ] instructions executed if [ instructions ] the expression expr_choix takes one of the values from the list of the expressionsexpr_v. } [ When Default [ : ] instructions executed if [ instructions ] the expression expr_choix has taken none of the values of the expressionsexpr_v. ] Endcase
|
Element |
Description |
Restrictions |
|
expr_choix |
Expression whose value allows the choice of an alternative. |
None. |
|
expr_v |
Expression whose value is compared to that of expr_choix. |
Of the same type as expr_choix. |
# Depending on the value of CHOIX, a particular action will be performed.
# If "R" is chosen, nothing is done.Case toupper(CHOIX)
When "A","E" : Gosub EFFACEMENT When "Q","F" : Goto FIN When "R" When "M" : Gosub MODIFICATION When Default Gosub AIDE Endcase # Alternative on the expression date$ that is compared to # other variables or complex expressions #Case date$
When [29/05/1959] Infbox "It is my birthdate" Gosub ANNIVERSAIRE When [18/06/1944],[08/05/1945],[11/11/1918] Infbox "It's a historical date" Gosub COMMEMORATION When DATE_LIMITE+DELAI_GRACE Infbox "Pay your tax bill by tonight!" Gosub PERCEPTEUR When Default Infbox "Nothing special today" Endcase
Case is used to allow alternatives within a routine, according to the value of an expression that may be compared to lists of values.
One alternative at the most is executed (a "case" is the same as If … Elsif ... Else ... Endif). If there is no When Default clause, and if no value matches the expression, no instruction limited by "case" will be run.
No instruction may be placed within the "case" and the first "when" (not even a comment).
When a "when" is not followed by any instruction before the next "when" there is no action to be performed, unlike certain languages such as C. In making the same choice for a series of values, this series must be put into one list, preceded by a "when".
|
Error |
Description |
|
ERMODE (10) |
The expression expr_v is a type not comparable to expr_choix. |
|
|