I am sure you know that this following script (which takes 12 sec to run):
set L to {}
set total to 0
set bignum to 20000
repeat with i from 1 to bignum
set end of L to i
end repeat
repeat with i from 1 to bignum
set total to total + (item i of L)
end repeat
can be much faster if written like this:
set L to {}
set refL to a reference to L
set total to 0
set bignum to 20000
repeat with i from 1 to bignum
set end of L to i
end repeat
repeat with i from 1 to bignum
set total to total + (item i of refL)
end repeat
total -- 12502500, and it took less than a second
But why I cannot implement it into my nested-loop below (which is a simplified version of a loop I need, which is a bit too slow. My script recursively compare one element of a list with all the others, and then it moves to the next. It started from the bottom, and at the end of each loop, it deletes the element just checked, to avoid repetition):
set my_Looped_List to {}
set ref_my_Looped_List to a reference to my_Looped_List
repeat with a from 1 to 300
set the end of my_Looped_List to a as string
end repeat
set my_text2 to ""
repeat with i from (length of ref_my_Looped_List) to 1 by -1
set my_item_outerloop to item i of ref_my_Looped_List
repeat with x from (length of ref_my_Looped_List) to 1 by -1
set my_item_innerloop to item x of ref_my_Looped_List
set my_text2 to my_text2 & (my_item_outerloop & " " & my_item_innerloop) & return
end repeat
set ref_my_Looped_List to reverse of rest of reverse of ref_my_Looped_List
end repeat
display dialog my_text2
Why I cannot use the “reference” trick in my script?
Thanks !