[Lazarus] What is the most efficient construction?

Sven Barth pascaldragon at googlemail.com
Mon Jul 29 07:53:46 CEST 2024


Arí Ricardo Ody via lazarus <lazarus at lists.lazarus-ide.org> schrieb am So.,
28. Juli 2024, 13:45:

> Hi guys
>
> A question that I have had for a long time:
>
> Suppose I have the variable
>
> list:TStringList
>
> and I want to iterate through the items through the items in list.
>
> Between the construction:
>
> For i := 0 to list.Count - 1 do
> begin;
>   commands
> end;
>
> And the construction
>
> j := list.Count - 1;
> For i := 0 to j do
> begin;
>    commands
> end;
>
> Which would be the most efficient?
>
> I ask because I have the impression that in the first construction it will
> be necessary to generate code to determine the value list.Count - 1 at each
> iteration of the For loop.
>

These are the same, cause in Pascal unlike in C-like languages the end
condition of a for-loop is only evaluated once at the start of the loop.

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20240729/7d813fe8/attachment.htm>


More information about the lazarus mailing list