[Oberon] Multiple RETURN in a procedure
Chris Burrows
cfbsoftware at gmail.com
Mon Oct 24 23:35:01 CEST 2022
On Tue, Oct 25, 2022 at 7:03 AM August Karlstrom <fusionfile at gmail.com>
wrote:
> Another ugly aspect of return statements is that they potentially make
> the code lie. Consider this statement for instance:
>
> WHILE i < 100 DO
> ...
> END
>
> When we see the loop it's natural to conclude that it will go on until i
> >= 100. However, with return statements there is no such guarantee.
>
>
Yes indeed. Another (even worse?) lie is when a RETURN is used here:
FOR i := 0 TO 99 DO
...
END
It is natural to conclude that the loop will execute *exactly* 100 times.
However, with return statements there is no such guarantee.
What I would like to know is why the return statement was introduced in
> Modula-2. Was it to compensate for the removal of goto in Pascal?
>
> That is the opinion of Richard Gleaves, one of the earliest Modula-2
pioneers. In his book, *Modula-2 for Pascal Programmers*, he wrote:
"Pascal's GOTO statement is missing from Modula-2; in its place are the
LOOP/EXIT and RETURN statements and the standard procedure HALT. LOOP/EXIT
statements are used to express repetitive statement sequences which contain
several exit points. RETURN is a limited form of GOTO; it transfers control
to the end of the current procedure. HALT terminates the currently running
program."
https://link.springer.com/book/10.1007/978-1-4613-8531-8
In that context they were a step in the right direction.
Regards,
Chris Burrows
CFB Software
https://www.astrobe.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20221025/1d794364/attachment.html>
More information about the Oberon
mailing list