Re: [fpc-pascal] Legitimate use of for and break

2023-06-19 Thread Steve Litt via fpc-pascal
Hairy Pixels via fpc-pascal said on Sun, 18 Jun 2023 08:04:23 +0700

>> On Jun 18, 2023, at 1:07 AM, tsie...@softcon.com wrote:
>> 
>> This is interesting, because it's the first time I've ever seen
>> "break" as a valid command in pascal, and I've been using pascal
>> since the mid/late 80s.  All kinds of dialects too, and I've never
>> seen break as a keyword.  C, Python, Perl, sure, even shell scripts,
>> but pascal? Never seen it used before.  Is this a relatively new
>> addition to fpc or something?  
>
>I don't remember break NOT being in Pascal. How did you exit a loop
>otherwise, goto? Break is common in basically all languages now. Can't
>think of a language I've used without it.

When I learned Pascal at Santa Monica Community College (SMC), the
professors repeatedly hammered home that a loop should have exactly one
entry point and one exit point. You don't exit until your test
condition goes false, and then you go down to the bottom of the loop
body and don't iterate further.. No matter how many levels of if
statements you had to use, you weren't supposed to use anything like
break, continue or exit in the loop. I don't remember whether those
keywords actually existed then.

I can still make a good argument for what my professors taught me, but
in the intervening years, I found break and especially continue
wonderful for increasing readability.


SteveT

Steve Litt 
Autumn 2022 featured book: Thriving in Tough Times
http://www.troubleshooters.com/bookstore/thrive.htm
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Legitimate use of for and break

2023-06-19 Thread Sven Barth via fpc-pascal

Am 18.06.2023 um 19:28 schrieb Travis Siegel via fpc-pascal:


On 6/18/2023 1:04 AM, Hairy Pixels via fpc-pascal wrote:
I don't remember break NOT being in Pascal. How did you exit a loop 
otherwise, goto? Break is common in basically all languages now. 
Can't think of a language I've used without it.


Use a variable, set the variable when you hit an exit criteria, then 
before repeating the loop, check the variable, if it's true, exit the 
loop (exit does this), or just craft the loop (easy to do if it's a 
loop until construct) so it exits the loop automatically.  Probably 
not as efficient as break, but since I didn't know it was a valid 
command, 


“Exit” leaves the surrounding *function*, not the surrounding *loop*.

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal