Array issue
Michael Lew
michaell at unimelb.edu.au
Thu Apr 2 20:08:22 EDT 2009
Dear listers
I have struck an unexpected issue with an array. I assumed that the two
following code snipets would be equivalent, but they are not.
Version 1
put random(10)-1 into tnum
add 1 to iHisto[tnum]
Version 2
add 1 to iHisto[(random(10)-1)]
Version 1 does what I expected, and, I guess is more readable and so
preferable for that reason. However, I can't see why the two versions differ
in their effects.
Here is the full code of my button for anyone who wishes to try it out (the
different versions are indicated with comments):
on mouseUp pMouseBtnNo
put 10000 into oreps
put 100 into ireps
set the cursor to busy
repeat oreps
put 0 into kount
repeat ireps
add 1 to kount
-- **next two lines
-- put random(10)-1 into tnum
-- add 1 to iHisto[tnum]
-- **OR the next one line
add 1 to iHisto[(random(10)-1)]
--
end repeat --inner
combine iHisto by return and comma
sort lines of iHisto numeric descending by item 2 of each
add 1 to ohisto[item 2 of line 1 of iHisto]
put empty into iHisto
end repeat --outer
combine oHisto with return and tab
sort lines of oHisto numeric ascending by word 1 of each
put oHisto into fld "OutputFld"
end mouseUp
Thanks,
Michael Lew
More information about the use-livecode
mailing list