Curious Repeat Counter Variable Behavior

I’m certain that I have been able to change the repeat counter variable within a repeat script in the past. Suddenly, I’m getting results that I do not understand.


repeat with i from 1 to 10
	display dialog ("i is equal to " & i)
	set i to (i + 2)
	display dialog ("heading into the repeat, i is equal to " & i)
end repeat

dialog results were

¢ “i is equal to 1”
¢ “i is equal to 3”
¢ “i is equal to 2”

Why is my set i to (i +2) not carrying through to the repeat?

i is already set and increasing in the repeat loop one step at a time. When you add 2 to it it increases i, inside of the loop by 2 then when you go back to the top of the loop it does the next logical step in the loop which is to set i to 2 You would have something like this
1
3
2
4
3
5
4
6
5
7
6
8
7
9
8
10
What are you attempting to do? Or is this just something you noticed?

Did it always work this way? I could have sworn that I have been able to change the repeat counter from within the repeat in the past.

I am trying to do just what I was indicating in the above example. I have a repeat set-up that generally needs to go straight through the repeat process. However, if a certain condition exists, I want to skip a step in the repeat.

More specifically I have a spreadsheet of order data that is being imported into Filemaker.

Basically, what is happening is that we are creating a parent record (the bill to/ship to info) and then adding it’s associated line items. For most orders, there is only one line item (the line item info appears on the same row in excel). However, within the repeat, i am checking to see if the next row in excel is for the same order, in which case, I want to only add line item info, and then skip that particular row the next time through the repeat.

The index variable i in the form

repeat with i from startValue to endValue

cannot be changed. Setting it has no effect for the “underlying” repeat loop counter

Weird. Ok, thanks. I think I know of a work around.

If you want to manage the counter yourself, I think you would want something more like this:

set I to 1
repeat
	--Do stuff
	set I to I + 2
	
	if I > 100 then exit repeat
end repeat

Got it. Thanks!