changing variable name with other variable in loop

I’m trying to change a variable name in a loop and use the counter to change the variable name. This is what I have tried.

repeat with y from 1 to 2
return title & y
end repeat

I’m trying to get back return title1 the first time and title2 the second time.

Hi,

there is no 2nd time, because the keyword return
either aborts the script, if used on top level of the script, or leaves a handler immediately, if used in a handler

ok, perhaps return is not the best example.
I was trying to set title1 to text carried out in the first iteration
and title2 to to text carried out in the second.
I left out all the other code because it was confusing.
I was using return just to check what I had in the results pane.
I thought it would be easier this way than typing the loop information twice.

Now I got it. :slight_smile:

Normally it’s not possible to change names of variables at runtime,
unless you do it with second level evaluation, that means running a literal string script,
which compiles at runtime.

But this might be more complicated than defining the variables separately

This will create the variables, can’t clam fame for this I got it off this site about a month ago

set variables to {}
repeat with i from 1 to 5
	set end of variables to "var" & i & ":\"\""
end repeat
set text item delimiters to ","
set variables to "{" & (variables as string) & "}"
set variables to run script variables

If you got working code please post it.

Why don’t you use a list, and call the items of the list

do you have any other ways of running a long loop twice and storing the result into 2 seperate variables?

I didn’t write the code loop and I don’t think it works with a list.
I tried it but got a response that seemed like it wasn’t working as a list.