[fpc-pascal] Legitimate use of for and break

Hairy Pixels genericptr at gmail.com
Sun Jul 2 02:44:32 CEST 2023

> On Jul 2, 2023, at 3:25 AM, Steve Litt via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> I tend to put continue statements at or near the top of the block, to
> summarily rule out some obvious irrelevant iterations without all sorts
> of if/then/else nesting. As a practical matter it's more readable and
> more maintainable.

Swift has decided to build this pattern into the language. I kind of like it but it's also kind of messy looking and a continue at the top of the block often is easier to read for me. In pascal it would look like this:

for item in list where item.value > 10 do

Which would be the same as:

for item in list do
    if item.value <= 10 then

or with traditional for loops but this really looks bad.

for i := 0 to list.Count - 1 where list[i] > 10 do

Ryan Joseph

More information about the fpc-pascal mailing list