[fpc-pascal] Legitimate use of for and break

Hairy Pixels genericptr at gmail.com
Fri Jun 16 04:57:36 CEST 2023

> 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? It's an array with a terminator string? Probably the length of the array should be set instead of doing string compares every loop.

program fordo;
var words: array[1..6] of string;
var ss: integer; 

for ss := 1 to 6 do
   words[ss] := '~';

words[1] := 'One';
words[2] := 'Two';
words[3] := 'Three';

for ss := 1 to 6 do
   if words[ss] = '~' then
      write(words[ss], '    ');


Ryan Joseph

More information about the fpc-pascal mailing list