[fpc-devel] Semicolon before else

Nikolai Zhubr zhubr at mail.ru
Fri Jan 29 17:07:41 CET 2010


29.01.2010 14:47, Juha Manninen:
[trim]
> There are some cases already where you can use a semicolon or leave it out.

Not exactly, IMHO. The original point (AFAIK) was that semicolon is a 
separator. That is, it is to be used _between_ operators, not _inside_ 
of. And in accordance, originally pascal's "case" operator didn't 
feature the "else" part at all, so it was all clear and logical. You 
were always free to add as much semicolons as you wish, but _only_ where 
allowed by syntax - _between_ operators. Like:

begin
   DoThing1;
   DoThing2;;
   DoThing3;;;
   ;;;;;
end;

This would be perfectly valid even with 25 years' ago compilers.
The last semicolon before "end" was never a requirement, because "end" 
is not an operator, so there is simply nothing to separate from. If you 
still put semicolon before the "end", it means you just add an implicite 
empty operator. You can do it just after "begin" if you like - it is 
harmless, though syntactically useless as well.
(And yes, I also have ; before "end" most of the time because of 
copy-pasting and typing reflex)

Nikolai

> Like :
>
> begin
>    if a>  100 then
>      DoThing1
>    else if a>  50 then
>      DoThing2
>    else if a>  10 then
>      DoThing3
>    else
>      DoThing4
> end
>
> You don't need a semicolon after the last DoThing4 because it is followed by
> END. That is handy when you need to change order and copy/paste those lines,
> and none of them has semicolon.
> However :
>
> begin
>    if a>  100 then
>      DoThing1
>    else if a>  50 then
>      DoThing2
>    else if a>  10 then
>      DoThing3
>    else
>      DoThing4;
>    FinalAction;
> end
>
> Now you needed the semicolon.
> Why not allow this, for pragmatic reasons:
>
>
> begin
>    if a>  100 then
>      DoThing1;
>    else if a>  50 then
>      DoThing2;
>    else if a>  10 then
>      DoThing3;
>    else
>      DoThing4;
>    FinalAction;
> end
>
> You can already add semicolons for example after END even they are not
> required.
>
> This has the same spirit as Perl's array syntax which allows a comma also
> after the last item. It is handy when reordering or adding items. It may be
> wrong philosophically or technically (or something) but it works and makes
> things easier.
> (This would be another improvement for Pascal const array syntax, too, but
> let's not go there now. It need its own thread.)
>
>
> Regards,
> Juha Manninen
>
>
>
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel




More information about the fpc-devel mailing list