I asked this question a couple of days ago but because i think I worded it incorrectly I didnt get the answers I was looking for. Ill try to clarify my request. If I have a list of variables named variable1, variable2, variable3 and so on. How do I write a loop that evaluates each variable in order and then executes a keystroke (Im working with a non-scriptable application so I have to use system events) based on the value of the variable being blank or containing an x, and ends the loop if the value is t. Im mostly concerned with how to evaluate each statement in succession and increment to the next variable for the next loop.
You can’t write a loop based on variable names.
If you’re using a fixed number of variables, you can put their values into a list and loop through that:
set listVariable to {variable1, variable2, variable3}
repeat with i from 1 to (count listVariable)
set thisValue to item i of listVariable
-- Do something with thisValue.
end repeat
If you don’t know how many values there’ll be, use just one variable with a list value and append values to that in order as you get them:
set listVariable to {}
set end of listVariable to firstResult
set end of listVariable to secondResult
set end of listVariable to yetAnotherResult
set end of listVariable to etc
repeat with i from 1 to (count listVariable)
set thisValue to item i of listVariable
-- Do something with thisValue.
end repeat
Thank you for this Nigel. I appreciate the help. I think this will work perfectly.
Christopher