Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: cycling

From: joel:neely:fedex at: 6-Jul-2001 13:33

Jeff Kreis wrote:
> > Given a set of M "index" values, what's the simplest way to > > cycle through them, both forward and backward? > > "A set of M 'index' values" -- you mean a block? >
No, I was referring to manipulating the value of a counter. Given a variable set to an integer within a restricted range of M values (either 0 .. M-1 or 1 .. M), what is the simplest way to step that variable to the next or previous value within the range, with "wrap-around" at either end of the range. If the range is 0 .. 4, then successive steps forward from 3 would produce 4, 0, 1, 2, 3, 4, 0, 1, 2, ... If the range is 1 .. 5, then successive steps backward from 3 would produce 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, ... Hope that's clearer. -jn- ___________________________________________________________________ The purpose of computing is insight, not numbers! - R. W. Hamming joel'dot'neely'at'fedex'dot'com