[fpc-devel] Fwd: While - Otherwise Statement
lazarus at mfriebe.de
Mon Oct 12 21:43:24 CEST 2015
On 12/10/2015 20:01, Max Nazhalov wrote:
>>> I can't think of a use case either. And just because another language
>>> provides such a solution, does not imply that FPC should.
(despite my earlier contribution)
Discussion of the feature below, is regardless of it not being desirable
(in any form)
>>> As to achieving
>>> the functionality in FPC:
>>> if cond then
>>> while cond do
>> That's what I've thought about from the beginning of this discussion..
Actually the above does not represent what the actual feature request is
The "else" is to be executed, after the while (even if the while looped
But it is to be skipped if the while exited via break (and only then).
For that reason "else" or "otherwise" are badly chosen keywords. Because
they imply a different function.
Further what is so special about the case "finishing a while loop
without break (including 0 iterations)"?
If that case deserves special attention then surely the following also
need (and no one should want all that)
initialize // run before the 1st loop, if there is going to be at
least one loop
do // each loop
finalize // run after last loop, if there was at least one
finalizeThen // run after last loop, if there was at least one //
only if no break
finalizeCatch // run after last loop, if there was at least one //
only if a break happened
then // finish, without break; or zero loops
catch // only on break
else // if there was no loop at all (condition was wrong, before
first loop already)
There are all equally (none-) important. Have one have all.
Better have none.
> The only drawback is that "cond" is calculated twice instead of once
> before the actual loop body -- not all will be happy.. ;-)
Thats an issue for the optimizer. no need to change the language.
More information about the fpc-devel