Introduces a "multiple-selection" control structure.
A multiple-selection control structure consists of several alternative blocks of statements. The first of these is introduced by a CASE statement. This has a single parameter, which is an expression that must yield a single number. Subsequent blocks are each introduced by an OR statement. There can then be a final block, introduced by an ELSE statement. The whole structure is terminated by an ENDCASE statement. Thus the general form is: first
then either none, one or several blocks of statements of the form
then, if required, a block of the form
and finally the statement
GenStat rounds the expression in the CASE expression to the nearest integer, k say, and then executes the kth block of statements. If there is no kth block present (as for example if k is negative) the block of statements following the ELSE statement is executed, if there is such a block; otherwise an error diagnostic is given.
This example prints the salient details about each day in the song The twelve days of Christmas. The scalar Day indicates which day it is.
PRINT 'a partridge in a pear tree'
PRINT 'two turtle doves and a partridge in a pear tree'
PRINT 'three French hens, two turtle doves \
and a partridge in a pear tree'
PRINT 'four calling birds, three French hens ...'
PRINT 'five gold rings ...'
PRINT 'six geese a-laying ...'
PRINT 'seven swans a-swimming ...'
PRINT 'eight maids a-milking ...'
PRINT 'nine drummers drumming ...'
PRINT 'ten pipers piping ...'
PRINT 'eleven ladies dancing ...'
PRINT 'twelve lords a-leaping ...'
PRINT 'sorry, no delivery today'
CASE statements can be nested to any depth.
Directives: OR, ELSE, ENDCASE, EXIT, IF, ELSIF, ENDIF, FOR, ENDFOR, CALCULATE.