MacharSoft UniCOMAL FAQs - The CASE statement

The CASE Statement in UniComal

The UniComal CASE structure will not accept "range switches" such as WHEN > 70, unlike Acorn Comal which does. There is, however, a way to provide such switches in UniComal, as shown in this example:-

	CASE mark# OF
	    WHEN mark# * (mark# > 70)
		grade# := 1
	    WHEN mark# * (mark# > 60)
		grade# := 2
	    OTHERWISE
		grade# := 7
	ENDCASE

This works because the logical expression (mark# > 70) evaluates to 1 if TRUE, and to 0 if FALSE. So if, for example, mark# has the value 73, then the expression 'mark#*(mark# >70) evaluates to 73, which matches the CASE.

This workaround cannot be used with string values, however, since there is no meaningful multiplication operator for strings. When using string values, if a range switch is required, the IF .. THEN .. ELIF .. ELSE .. ENDIF structure can be used, like this:

	IF target$ > "Z" THEN
	    PRINT target$, " does not start with a capital letter."
	ELIF target$ > "M" THEN
	    PRINT target$, " is in the second half of the alphabet."
	ELIF target$ >= "A" THEN
	    PRINT target$, " is between A and M."
	ELSE
	    PRINT target$, " does not start with a capital letter."
	ENDIF


Edited 10-Nov-2001