Using a loop to name a variable and assign value
Posted: Fri Jan 27, 2017 9:18 am
Here's a snippet:
repeat with i=1 to thisNum
put random(5) into thisDig
if i = 1 then put thisDig into Numb1
if i = 2 then put thisDig into Numb2
if i = 3 then put thisDig into Numb3
if i = 4 then put thisDig into Numb4
if i = 5 then put thisDig into Numb5
end repeat
I tried put thisDig into "Numb" & i, but that was an error.
I tried a few other things, but nothing works except the approach of spelling out what is to happen for each iteration (which would be quite rough with a larger loop).
Ideas?
repeat with i=1 to thisNum
put random(5) into thisDig
if i = 1 then put thisDig into Numb1
if i = 2 then put thisDig into Numb2
if i = 3 then put thisDig into Numb3
if i = 4 then put thisDig into Numb4
if i = 5 then put thisDig into Numb5
end repeat
I tried put thisDig into "Numb" & i, but that was an error.
I tried a few other things, but nothing works except the approach of spelling out what is to happen for each iteration (which would be quite rough with a larger loop).
Ideas?