[Oberon] CASE statement

Chris Burrows chris at cfbsoftware.com
Fri Apr 9 03:15:05 CEST 2021


> -----Original Message-----
> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of Duke
> Normandin
> Sent: Friday, 9 April 2021 8:02 AM
> To: Oberon
> Subject: [Oberon] CASE statement
> 
> Is it possible to have execute a block of code - BEGIN .... END for one or
> more CASE alternatives? I'm trying to simulate the following C code:
> 
>  switch (c){
>     case '1':
>       printf("Enter a number/temperature to convert: ");
>       scanf("%f", &temp);
>       printf("Your input was %.1lf Fahrenheit\n", temp);
>       printf("That's %.1lf in Celsius\n", fahr2cels(temp));
>       break;
> --


Yes you can have blocks of code (multiple statements) in each CASE
alternative in an Oberon-2 program. For example the CASE example in the
Oberon-2 Report is:

CASE ch OF
"A" .. "Z": ReadIdentifier
| "0" .. "9": ReadNumber
| " ' ", ' " ': ReadString
ELSE SpecialCharacter
END

However you don't need both BEGIN and END if the case has more than one
statement. The BEGIN is redundant. The end of each block is indicated by
"|", "ELSE" or "END" e.g.

CASE ch OF
"A" .. "Z": 
  sym := ident;
  ReadIdentifier
| "0" .. "9": 
  sym := number;
  ReadNumber
| " ' ", ' " ':
  sym := string  
  ReadString
ELSE 
  sym := char; 
  SpecialCharacter
END
  
Regards,
Chris

Chris Burrows
CFB Software
https://www.astrobe.com/RISC5




More information about the Oberon mailing list