Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-12

else and otherwise in a case statement

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mark Morgan Lloyd

I've been doing a bulk replace of 'case..else' to 'case..otherwise' to eliminate possible ambiguities that have bitten me in the past, and have noticed something interesting under 2.6.4 on x86 Linux.

This is OK:

         Ord('.'): case shiftState of
                     unshifted: mechCode := Corr_88_Period;
                     shifted:
                   else
                   end;

This is an error:

         Ord('.'): case shiftState of
                     unshifted: mechCode := Corr_88_Period;
                     shifted:
                   otherwise
                   end;

I can fix it like this:

         Ord('.'): case shiftState of
                     unshifted: mechCode := Corr_88_Period;
                     shifted: ;
                   otherwise
                   end;

But that grates since I was brought up on ; being a statement separator rather than a terminator. Alternatively this is OK:

         Ord('.'): case shiftState of
                     unshifted: mechCode := Corr_88_Period;
                     shifted:
                   end;

but I like having the regular code (in some cases there are active otherwise clauses, and I spent enough time with Modula-2 to prefer enumerating all possibilities).

Is this difference expected, and what is the best workaround?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Howard Page-Clark
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote
I've been doing a bulk replace of 'case..else' to 'case..otherwise' to eliminate possible ambiguities that have bitten me in the past, and have noticed something interesting under 2.6.4 on x86 Linux.

How can "else" be ambiguous within a case statement?

Howard

---
This email has been checked for viruses by Avast antivirus software. http://www.avast.com

Ewald
to Howard Page-Clark
Howard Page-Clark wrote 6 lines
On 11/12/2014 21:07, Mark Morgan Lloyd wrote: > I've been doing a bulk replace of 'case..else' to 'case..otherwise' to > eliminate possible ambiguities that have bitten me in the past, and have > noticed something interesting under 2.6.4 on x86 Linux. How can "else" be ambiguous within a case statement?

If one omits the trailing semicolon (the one that's commented), the else becomes ambiguous:

Case Something of
    Value1: ;
    Value2: If Condition Then DoSomething (*;*)
Else
End;
Ewald
Mark Morgan Lloyd
to Ewald
Ewald wrote 15 lines
On 12/11/2014 11:13 PM, Howard Page-Clark wrote: > On 11/12/2014 21:07, Mark Morgan Lloyd wrote: >> I've been doing a bulk replace of 'case..else' to 'case..otherwise' to >> eliminate possible ambiguities that have bitten me in the past, and have >> noticed something interesting under 2.6.4 on x86 Linux. > How can "else" be ambiguous within a case statement? If one omits the trailing semicolon (the one that's commented), the else becomes ambiguous: Case Something of Value1: ; Value2: If Condition Then DoSomething (*;*) Else End;

Yes, that's the one. When I raised it it was pointed out to me that the otherwise form was intended as a drop-in replacement to avoid this.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]