Re: Looping though a numerically indexed array

2020-09-10 Thread Dan Friedman via use-livecode
David,

Maybe there are better ways, but here's what I always do when I have an array 
with numbered keys...

put the keys of pArray into aKeys
sort lines of aKeys numeric
repeat for each line k in aKeys
   //do something with pArray[k]
end repeat

Hope that helps.   :)

-Dan
 

On 9/10/20, 2:39 PM, "use-livecode on behalf of David Bovill via use-livecode" 
 wrote:

Ah that explains it. The extents works but I seem to remember for each is 
considerably faster
On 2 Sep 2020, 16:29 +0100, Brian Milby via use-livecode 
, wrote:
> As long as the array is indexed starting at 1 with no gaps it should work 
by looping for each element. I just did a quick test to confirm. I built a 100 
element array and it looped in order. I deleted 2 keys and then it didn’t. I 
then added those 2 missing keys back and it worked again.
>
> Sent from my iPhone
>
> > On Sep 2, 2020, at 10:55 AM, David Bovill via use-livecode 
 wrote:
> >
> > I’m pretty sure there must be a way to efficiently loop through 
numerically indexed arrays
> >
> > Repeat for each key and repeat for each element does not seem to sort 
the keys in numeric order,. Of course I can get the keys and sort them before 
repeating - but is there a more efficient way?
> > ___
> > use-livecode mailing list
> > use-livecode@lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your 
subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your 
subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your 
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Looping though a numerically indexed array

2020-09-10 Thread David Bovill via use-livecode
Ah that explains it. The extents works but I seem to remember for each is 
considerably faster
On 2 Sep 2020, 16:29 +0100, Brian Milby via use-livecode 
, wrote:
> As long as the array is indexed starting at 1 with no gaps it should work by 
> looping for each element. I just did a quick test to confirm. I built a 100 
> element array and it looped in order. I deleted 2 keys and then it didn’t. I 
> then added those 2 missing keys back and it worked again.
>
> Sent from my iPhone
>
> > On Sep 2, 2020, at 10:55 AM, David Bovill via use-livecode 
> >  wrote:
> >
> > I’m pretty sure there must be a way to efficiently loop through numerically 
> > indexed arrays
> >
> > Repeat for each key and repeat for each element does not seem to sort the 
> > keys in numeric order,. Of course I can get the keys and sort them before 
> > repeating - but is there a more efficient way?
> > ___
> > use-livecode mailing list
> > use-livecode@lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your 
> > subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Looping though a numerically indexed array

2020-09-02 Thread Bob Sneidar via use-livecode
It appears I have that backwards?

Bob S


> On Sep 2, 2020, at 8:28 AM, Bob Sneidar  wrote:
> 
> Ditto, and I am not sure what noticeable impact one method would have over 
> another. There was some blurb a long time ago about how these keys are 
> internally sorted. I believe what was proposed is that a set of NUMERIC keys 
> beginning with 0 would actually sort correctly. 
> 
> Bob S
> 
> 
>> On Sep 2, 2020, at 8:24 AM, Ralph DiMola via use-livecode 
>>  wrote:
>> 
>> David,
>> 
>> Nope you have to sort them NUMERIC. As you said this is the only way I know 
>> of. I do this all the time. I don't know of any other way.
>> 
>> put the keys of tMyArray into tKeys
>> sort lines of tKeys numeric
>> repeat for each line tKey in tKeys
>> 
>> -- do what you want with tMyArray[tKey]
>> -- this line will put the array data in the message box (assuming there is 
>> no other sub keys in each numeric array entry).
>> put tMyArray[tKey] into tMyVar
>> 
>> end repeat
>> 
>> Ralph DiMola
>> IT Director
>> Evergreen Information Services
>> rdim...@evergreeninfo.net
>> 
>> -Original Message-
>> From: use-livecode [mailto:use-livecode-boun...@lists.runrev.com] On Behalf 
>> Of David Bovill via use-livecode
>> Sent: Wednesday, September 02, 2020 10:55 AM
>> To: How to use LiveCode
>> Cc: David Bovill
>> Subject: Looping though a numerically indexed array
>> 
>> I’m pretty sure there must be a way to efficiently loop through numerically 
>> indexed arrays
>> 
>> Repeat for each key and repeat for each element does not seem to sort the 
>> keys in numeric order,. Of course I can get the keys and sort them before 
>> repeating - but is there a more efficient way?
>> ___
>> use-livecode mailing list
>> use-livecode@lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription 
>> preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
>> 
>> ___
>> use-livecode mailing list
>> use-livecode@lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription 
>> preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> 

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Looping though a numerically indexed array

2020-09-02 Thread Alex Tweedly via use-livecode
If the array is indexed from 1 with no gaps, you can do

repeat with I = 1 to item 2 of line 1 of the extents of myArray

Alex


> On 2 Sep 2020, at 15:54, David Bovill via use-livecode 
>  wrote:
> 
> I’m pretty sure there must be a way to efficiently loop through numerically 
> indexed arrays
> 
> Repeat for each key and repeat for each element does not seem to sort the 
> keys in numeric order,. Of course I can get the keys and sort them before 
> repeating - but is there a more efficient way?
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Looping though a numerically indexed array

2020-09-02 Thread Bob Sneidar via use-livecode
Ditto, and I am not sure what noticeable impact one method would have over 
another. There was some blurb a long time ago about how these keys are 
internally sorted. I believe what was proposed is that a set of NUMERIC keys 
beginning with 0 would actually sort correctly. 

Bob S


> On Sep 2, 2020, at 8:24 AM, Ralph DiMola via use-livecode 
>  wrote:
> 
> David,
> 
> Nope you have to sort them NUMERIC. As you said this is the only way I know 
> of. I do this all the time. I don't know of any other way.
> 
> put the keys of tMyArray into tKeys
> sort lines of tKeys numeric
> repeat for each line tKey in tKeys
> 
> -- do what you want with tMyArray[tKey]
> -- this line will put the array data in the message box (assuming there is no 
> other sub keys in each numeric array entry).
> put tMyArray[tKey] into tMyVar
> 
> end repeat
> 
> Ralph DiMola
> IT Director
> Evergreen Information Services
> rdim...@evergreeninfo.net
> 
> -Original Message-
> From: use-livecode [mailto:use-livecode-boun...@lists.runrev.com] On Behalf 
> Of David Bovill via use-livecode
> Sent: Wednesday, September 02, 2020 10:55 AM
> To: How to use LiveCode
> Cc: David Bovill
> Subject: Looping though a numerically indexed array
> 
> I’m pretty sure there must be a way to efficiently loop through numerically 
> indexed arrays
> 
> Repeat for each key and repeat for each element does not seem to sort the 
> keys in numeric order,. Of course I can get the keys and sort them before 
> repeating - but is there a more efficient way?
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


RE: Looping though a numerically indexed array

2020-09-02 Thread Ralph DiMola via use-livecode
David,

Nope you have to sort them NUMERIC. As you said this is the only way I know of. 
I do this all the time. I don't know of any other way.

put the keys of tMyArray into tKeys
sort lines of tKeys numeric
repeat for each line tKey in tKeys

-- do what you want with tMyArray[tKey]
-- this line will put the array data in the message box (assuming there is no 
other sub keys in each numeric array entry).
put tMyArray[tKey] into tMyVar

end repeat

Ralph DiMola
IT Director
Evergreen Information Services
rdim...@evergreeninfo.net

-Original Message-
From: use-livecode [mailto:use-livecode-boun...@lists.runrev.com] On Behalf Of 
David Bovill via use-livecode
Sent: Wednesday, September 02, 2020 10:55 AM
To: How to use LiveCode
Cc: David Bovill
Subject: Looping though a numerically indexed array

I’m pretty sure there must be a way to efficiently loop through numerically 
indexed arrays

Repeat for each key and repeat for each element does not seem to sort the keys 
in numeric order,. Of course I can get the keys and sort them before repeating 
- but is there a more efficient way?
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Looping though a numerically indexed array

2020-09-02 Thread Brian Milby via use-livecode
As long as the array is indexed starting at 1 with no gaps it should work by 
looping for each element.  I just did a quick test to confirm.  I built a 100 
element array and it looped in order.  I deleted 2 keys and then it didn’t.  I 
then added those 2 missing keys back and it worked again.

Sent from my iPhone

> On Sep 2, 2020, at 10:55 AM, David Bovill via use-livecode 
>  wrote:
> 
> I’m pretty sure there must be a way to efficiently loop through numerically 
> indexed arrays
> 
> Repeat for each key and repeat for each element does not seem to sort the 
> keys in numeric order,. Of course I can get the keys and sort them before 
> repeating - but is there a more efficient way?
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode