[fpc-devel] Semicolon before else

Graeme Geldenhuys graemeg.lists at gmail.com
Tue Jan 26 07:42:24 CET 2010


David W Noon wrote:
> 
> [snip]
>> case p of
>> '1': do_1;
>> '2' if (q > 0) then do_2;
>> else do_3;
>> end;
>>
>> It is not clear if else should be part of branch '2' (part of if
>> statement), or else branch for case.
> 
> A quick examination of Jensen & Wirth's original Pascal grammar will
> tell you how that should be parsed: in Pascal there is *never* a
> semi-colon between the "then" clause and the "else" in an "if"
> statement.

I must agree with David. The idea of the extra semi-colon just adds
confusion and no extra value.

Example where 'do_3 is part of the case statement:
  case p of
    '1': do_1;
    '2' if (q > 0) then do_2;
    else do_3;
  end;


Example where 'do_3' is part of the '2' if/else statement:
  case p of
    '1': do_1;
    '2' if (q > 0) then do_2
        else do_3;
  end;


Syntax and understanding is as clear as rain. Adding extra semi-colon, as
you suggested, is not.

As for the 'otherwise' syntax. You are correct, I have never heard or seen
it before. :-) But it is documented in the FPC Language Reference section
10.2.2.

Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/




More information about the fpc-devel mailing list