[fpc-pascal] Legitimate use of for and break
Dennis Lee Bieber
wlfraed at ix.netcom.com
Tue Jun 20 17:56:10 CEST 2023
On Tue, 20 Jun 2023 14:05:04 +0700, Hairy Pixels via fpc-pascal
<fpc-pascal at lists.freepascal.org> declaimed
the following:
>
>Educators continuously have stupid ideas that don't work out as intended in the real world. I would love to see them make a real program that does something difficult and not use early breaks.
>
>I assume them they forbid early exits in functions also or is the loop special for them?
>
One-IN/One-OUT was a tenet of Structured Programming as used in the
late 1970s/early 1980s -- and yes, it also applied to subprograms
(functions and routines both for those languages that differentiated) and
IF statements.
This is also about the same time that Chapin/Nassi-Schneiderman charts
were developed to be used in place of free-form flow-charts. N-S chart
elements enforced a one-in/one-out diagramming of the logic (no GOTO
equivalent). If it required nesting IF statements to avoid ad-hoc GOTO, so
be it. Mapping those structures to "unstructured" languages (COBOL 74,
FORTRAN IV, BASIC, etc.) might require reverting to GOTO -- but an
organization's programming standards guidelines would define exactly how a
structured entity would be mapped, and could thereby be reviewed for
compliance.
{structured}
if condition then
do stuff
else
do other stuff
endif
{FORTRAN IV}
if .not. (condition) then goto {elselabel}
do stuff
goto {endiflabel}
{elselabel} continue
do other stuff
{endiflabel} continue
[FORTRAN "CONTINUE" is a NOP statement, often used as the target of a GOTO
as one could edit the subsequent actions without having to keep moving the
label from statement to statement]
BREAK/CONTINUE tended to come later, when they were deemed a safe (ie;
structured) alternative to the GOTO statement.
More information about the fpc-pascal
mailing list