Simple array question

Martin Baxter martin at materiaprima.fsnet.co.uk
Fri Oct 1 06:41:17 EDT 2004


>Alex Tweedly wrote:
>
>>At 20:25 30/09/2004 -0700, Mark Brownell wrote:
>
>>What do you get for this? I'm not sure I did this right. [untested]
>>
>>  repeat for each element i in x
>>       put i & return after tResults
>>   end repeat
>>   put tResults into field 2
>
>I don't see anything in the documentation of "element" or "for each
>element" that assures me they will be taken in the correct order.

You shouldn't rely on it. The order may be correct in some circumstances
(eg immediately after a split command and before you have modified the
array), but mostly the ordering of elements will not be numeric.

For example:

put "a,b,c,d,e,f,g,h,i" into tvar
split tvar by comma

Then the resulting array is like this:

[1]a
[2]b
[3]c
[4]d
[5]e
[6]f
[7]g
[8]h
[9]i

But as soon as you do:

put "j" into tvar[10]

The element order would then be:

[1]a
[10]j
[2]b
[3]c
[4]d
[5]e
[6]f
[7]g
[8]h
[9]i

HTH

Martin Baxter




More information about the Use-livecode mailing list