Updating variables in handlers & repeat loops

Hi All

When I run the following script ‘x’ returns.

(2)
(2)
(2)
(2)
(2)

but I was expecting.

(2)
(3)
(4)
(5)
(6)


set x to 1

repeat 5 times	
	addOne(x)
end repeat

on addOne(x)
	set x to x + 1
	log x
end addOne

I’m guessing that I need to return ‘x’ back to the repeat loop, but I don’t know how?

Thanks again

Shane

set x to 1

repeat 5 times
	set x to addOne(x)
end repeat

on addOne(y)
	set y to y + 1
	log y
	return y
end addOne

thank you!

Or using references:


set x to 1

repeat 5 times
	addOne(a reference to x)
end repeat

on addOne(x)
	set contents of x to x + 1
	log x
end addOne