change variable names based on values in repeat loop

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Re: change variable names based on values in repeat loop

Post by Newbie4 » Sun Jun 30, 2013 4:17 am

@rkriesel
If you take out the lines in your first example that reference "x" (which is not used anyway), then both of your examples are the same number of lines ??? So I see no difference in compactness.

If you factor in the time to set up the keys to the array as well as the extra time it takes to handle array references in the loop, the array example runs longer.

I should think arrays are better only if you are doing lookups on data, not handling data sequentially or every element in it.
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

rkriesel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 119
Joined: Thu Apr 13, 2006 6:25 pm

Re: change variable names based on values in repeat loop

Post by rkriesel » Sun Jun 30, 2013 8:41 am

Newbie4 wrote:@rkriesel
If you take out the lines in your first example that reference "x" (which is not used anyway), then both of your examples are the same number of lines ??? So I see no difference in compactness.

If you factor in the time to set up the keys to the array as well as the extra time it takes to handle array references in the loop, the array example runs longer.

I should think arrays are better only if you are doing lookups on data, not handling data sequentially or every element in it.
@Newbie4
The difference in compactness between my code snippets is

Code: Select all

value( "data" & z )
vs.

Code: Select all

data[ z ]
The former involves interpreting expressions at run time; the latter's lookup is conceptually simpler, and probably faster both to code and to execute.
Of course, YMMV, and the execution speed difference may or may not matter in any particular case.

The difference in compactness among the various posters' code is wider. Arrays seem to facilitate compactness of code.

-- Dick

PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Re: change variable names based on values in repeat loop

Post by PoLyGLoT » Sun Jun 30, 2013 3:59 pm

I appreciate all the feedback.

I have never used an array, so I cannot comment on that. I know that for my purposes, each of my "data" files (data2, data3, data4, data5, and data6) has a different number of lines, and different values. And the ordering is important - my analyses have to be limited to first data2, then data3, etc. I cannot combine lines from the different data files or anything like that.

At any rate, based on the comments and a little thinking I got it to work for my purposes.

Post Reply