[fpc-pascal] Legitimate use of for and break

Steve Litt slitt at troubleshooters.com
Fri Jun 16 08:19:57 CEST 2023


Hairy Pixels via fpc-pascal said on Fri, 16 Jun 2023 09:57:36 +0700

>> On Jun 16, 2023, at 6:07 AM, Steve Litt via fpc-pascal
>> <fpc-pascal at lists.freepascal.org> wrote:
>> 
>> Is http://sprunge.us/MOJIg4 a legitimate use of a for loop with
>> break? I know there are better ways to do it, but I'm just wondering
>> whether it's legitimate.  
>
>What are you trying to do exactly? 

Explore FPC.

> It's an array with a terminator
>string? Probably the length of the array should be set instead of
>doing string compares every loop.

I need to set it in the var declaration, right?

>
>program fordo;
>var words: array[1..6] of string;
>var ss: integer; 
>
>begin
>for ss := 1 to 6 do
>   words[ss] := '~';
^^^^^^^^^^^^^^^^^^^^ Is it legitimate to set elements inside a for loop?

>
>words[1] := 'One';
>words[2] := 'Two';
>words[3] := 'Three';
>
>for ss := 1 to 6 do
>   if words[ss] = '~' then
>      break
       ^^^^^      IS IT legitimate to use a break (or continue) inside
       a for loop?

Thanks,

SteveT

Steve Litt 
Autumn 2022 featured book: Thriving in Tough Times
http://www.troubleshooters.com/bookstore/thrive.htm


More information about the fpc-pascal mailing list