[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Looping through an array with FOR EACH


Il 15/01/26 12:44, BB ha scritto:
On 15/1/26 8:46 pm, Gianluigi wrote:
Hi everyone,

I seem to remember reading somewhere (perhaps in an email from Benoit?) that if you loop through an array with For Each in Gambas, you can't be sure of the correct sequence.
Did I dream it, or is it true?


I am going to interpret your "correct sequence" as "expected sequence". It is true. However rare to encounter.

There is chance that after manipulating an array (in many ways) that the order in which For Each iterates is not the same as the last "order" as determined by the operations on the array.

However, it is more a "beware of" rather than a rule.

I believe that he was just making people aware of this, rather than trying to scare them.

b


Admin and Bruce,

thank you for your replies.

My question stems from this post on the Gambas One forum:
https://gambas.one/forum/index.php?page=topicview&type=findpost&id=13792
The question was about how to construct and read a jagged array, and the answer above favored For Each over a simple loop with a counter. Since I know this is true for certain languages, I wanted to know if it was also true for Gambas.

If I understand Bruce's answer correctly, using counters is preferable with Gambas.

Regards
Gianluigi


Follow-Ups:
Re: Looping through an array with FOR EACHBrian G <brian@xxxxxxxxxxxxxxxx>
References:
Looping through an array with FOR EACHGianluigi <gradobag@xxxxxxxxxxx>
Re: Looping through an array with FOR EACHBB <adamnt42@xxxxxxxxx>