Hi,

In a «repeat» loop, I want to change variable 1 on «even» numbered loop and change variable2 on «odd» numbered loop. How can I determine if the loop is odd or even numbered ?

Thanks in advance.

Robert

Hi,

In a «repeat» loop, I want to change variable 1 on «even» numbered loop and change variable2 on «odd» numbered loop. How can I determine if the loop is odd or even numbered ?

Thanks in advance.

Robert

Hi, Robert.

```
repeat with i from 1 to 10
if (i mod 2 is 0) then
-- Even.
else -- (i mod 2 is 1)
-- Odd.
end if
end repeat
```

Thank you Nigel. I would have not found that one. Here is a little handler than can be helpful to add to anybody’s routine library …

```
on OddEven(theNumber)
if (theNumber mod 2 is 0) then
return "even"
else
return "odd"
end if
end OddEven
```

Regards.

Robert

You could toggle a Boolean variable to keep track.

```
set var1 to 1
set var2 to 100
set loopParity to false
repeat until var1 > 9 or var2 > 500
if loopParity then
set var1 to var1 + 2
else
set var2 to var2 + 50
end if
set loopParity to not (loopParity)
--display dialog "" & var1 & linefeed & var2 & linefeed & loopParity
end repeat
```

Thanks for your script.