Math challenge thing
Ken Ray
kray at sonsothunder.com
Sun Jul 30 14:17:33 EDT 2006
On 7/30/06 1:03 PM, "J. Landman Gay" <jacque at hyperactivesw.com> wrote:
> I had to write a loop the other day that cycled around a list of 4
> numbers. Usually when I need to do that, I like to use the following,
> where x is the current number that I want to increase:
>
> put (x mod 4)+1 into x
>
> This goes around and around, giving a value of x between 1 and 4. But
> this time I needed to include zero. I need a series "0,1,2,3". No matter
> how I tinkered, I couldn't get a zero out of it.
>
> I wrote it the long way: if x = 3 then put 0 into x
>
> But I got curious. Is there a way to do it the cool way? I'm a math
> idiot so maybe it's easy.
Couldn't you just use:
put (x mod 4) into x
as in:
on mouseUp
put 12 into tMax
repeat with x = 1 to tMax
put (x mod 4) & "," after fld 1
end repeat
end mouseUp
Result:
1,2,3,0,1,2,3,0,1,2,3,0,
The first number starts with "1", though. If you need it to start with 0,
you could do the same thing but start your loop with "0" instead of "1" and
go to (max -1):
on mouseUp
put 12 into tMax
repeat with x = 0 to (tMax-1)
put (x mod 4) & "," after fld 1
end repeat
end mouseUp
Result:
0,1,2,3,0,1,2,3,0,1,2,3,
HTH,
Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com
More information about the use-livecode
mailing list