[fpc-pascal] case statement

Adriaan van Os adriaan at adriaan.biz
Sun Dec 17 06:12:43 CET 2023


Tony Whyman via fpc-pascal wrote:

> Prospero Pascal was close to ISO Pascal (although I have lost my 
> original copy of ISO Pascal) and I would guess that the above is copied 
> from ISO Pascal.

You can find the ISO-7185 document on the internet, just search for "iso7185.pdf".

A less known aspect of the ISO-7185 Pascal case-statement is that it is an error if none of the 
case-conditions is met.

6.8 .3.5 Case-statements
The values denoted by the case-constants of the case-constant-lists of the case-list-elements of a
case-statement shall be distinct and of the same ordinal-type as the expression of the case-index
of the case-statement . On execution of the case-statement the case-index shall be evaluated . That
value shall then specify execution of the statement of the case-list-element closest-containing the
case-constant denoting that value . One of the case-constants shall be equal to the value of the
case-index upon entry to the case-statement ; otherwise, it shall be an error.

I find the idea of a "closest containing value" rather weird. For me, programming is strict logic, 
not finding something "closest".

Anyway, the innocent looking case-statement does have some interesting aspects.

> As an aside, I much prefer OTHERWISE to ELSE given that it is much closer to natural language. The IF...THEN..ELSE construct probably dates back to Algol 60 and I wonder why it was proposed. In normal English use, "else" is not used in this way. It usually follows another word, such as "anyone else", "anything else", "or else".
> 
> You might say
> 
> "If I go to town then I will be out. Otherwise, I will stay at home". I would never replace "otherwise" with "else" in such a sentence. "Else" belongs in a statement such "Does anyone else have a view".

Interesting observation !

Regards,

Adriaan van Os



More information about the fpc-pascal mailing list