Page 1 of 1

What do you call it when you loop around and arbitary number?

Posted: Wed Aug 12, 2009 7:51 am
by lucid
I'm stuck on a little programing script which basically counts to 3 and then goes back to 1 when it's done.
e.g. 1 = 1
      2 = 2
      3 = 3
      4 = 1

It's not really % or mod cause that would give
e.g. 1 = 1
      2 = 2
      3 = 0
      4 = 1

any ideas anyone?

Re: What do you call it when you loop around and arbitary number?

Posted: Wed Aug 19, 2009 8:51 pm
by calguy1000
Read the smarty manual.

Re: What do you call it when you loop around and arbitary number?

Posted: Wed Aug 19, 2009 10:58 pm
by calguy1000
Besides the fact that this is completely irrelevant to a content management system, that there are thousands of other places on the web that you could've asked this TRIVIAL question, and that you didn't explain any context (like what language you were trying to write it in). I thought I'd just give a small example of a solution.

Code: Select all

for( i = 0; i < 100000; i++ )
{
   n = i %3;
   printf("%d\n",n+1);
}