Arí Ricardo Ody via lazarus <lazarus@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

>
-- 
_______________________________________________
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus

Reply via email to