@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.
change variable names based on values in repeat loop
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: change variable names based on values in repeat loop
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/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
Re: change variable names based on values in repeat loop
@Newbie4Newbie4 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.
The difference in compactness between my code snippets is
Code: Select all
value( "data" & z )
Code: Select all
data[ z ]
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
Re: change variable names based on values in repeat loop
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.
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.