Atkinson dither algorithm & 'for each' loop
Bob Sneidar
bobsneidar at iotecdigital.com
Thu Oct 12 10:41:21 EDT 2017
That is correct Ben. It's not the repeat for each that is unreliable (probably a bad word to use here) but it is arrays which do not retain the sequence of key/values in the order they were put in.
To get around this, when possible use numbered keys, then:
put the keys of aMyArray into tKeyList
sort the lines of tKeyList numeric ascending
repeat for each line tKey in tKeyList
...
Bob S
> On Oct 12, 2017, at 04:48 , Ben Rubinstein via use-livecode <use-livecode at lists.runrev.com> wrote:
>
> Hi Peter,
>
>> One note of caution regarding the use of the "repeat for each" loop, whilst you will get a loop iteration for every value in the collection
>> (fldhexa3 in your example), you are not guaranteed the order in which they
>> will occur.
>
> Are you sure? My understanding has always been that chunk items, e.g.
> repeat for each [ byte | char | word | item | line] <var> in <container>
>
> will always be sequential (indeed that's why this structure is fast) - it's only when dealing with hashed arrays that the sequence is not reliable, i.e.
> repeat for each key <var> in <array>
> repeat for each element <var> in <array>
>
> Do you have experience to the contrary?
>
> best regards,
>
> Ben
More information about the use-livecode
mailing list