[fpc-devel] Fwd: While - Otherwise Statement

Martin Frb lazarus at mfriebe.de
Mon Oct 12 00:41:49 CEST 2015

On 11/10/2015 22:33, Tomas Hajny wrote:
> On Sun, October 11, 2015 22:48, Sven Barth wrote:
>   .
>   .
>> That "then" is a great idea! That would definitely not break anything and
>> it would make sense indeed:
>> === code begin ===
>> while bool do
>>    foo
>> then
>>    bar;
>> repeat
>>    foo;
>> until bool then
>>    bar;
>> === code end ===
> I'm afraid that I got lost in this discussion, but what exactly would be
> the supposed semantic difference between the behaviour compared to
> situation when there was a semicolon instead of 'then' there?
You mean compared to the otherwise solution?

The following is currently valid code:
case a of
   1: write;
   2: while a > 0 do dec(a)   // no semicolon
      write('a was neither 1 nor 2');

This code would continue to compile, but it would change meaning/behaviour.
So if somebody has code like that, in a million line project, which 
fails after otherwise was introduced, then it could be a long search for 
why it fails. (Easy to fix once found, but hard to find)

Besides "then" makes more sense (as in reading it as english description).

Both else/otherwise, to me read as: If the while block before was not 
executed at all.
In otherwords
   while a > 0 do write
   otherwise halt;
reads to me "halt" is an alternative to the "while". It gets executed if 
the while was never executde (a was already <= 0 when while was reached 

"then" in english may mean "after that" and that is what happens here. 
After the while do something.

More information about the fpc-devel mailing list