You can get that without an if. You need the ++ and % operators. Or even ++ and bitwise and (=&). But I don't think that is the pattern MG wanted.
Carey Brown wrote:. . . 0 1 2 3 0 1 2 3 0 1 2 3
What a good idea. Did you mean a Deque or its supertype, a Queue? I think both will work.You can do more or less the same with an array:-The 0, 1 at the beginning of the sequence are awkward, causing repeated code. Getting Carey's sequence is much easier:-The trick with &= 3 only works as a substitute for remainder by an exact power of 2.
Matthew Bendford wrote:. . . Dequeue . . .
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton