Jump to content

Increment a count by +4


jarvis

Recommended Posts

Did you think to test what the result of ($i % 4) would be for different values of $i? If you had it would have shown that you were on the right track, but made one flaw.

for($i=0; $i<14; $i++)
{
    echo "{$i} : mod 4 = " . ($i%4) . "<br>\n";
}

Here are the results of that test (I've highlighted the ones that I think you should pay attention to:

 

 

0 : mod 4 = 0

1 : mod 4 = 1
2 : mod 4 = 2
3 : mod 4 = 3
4 : mod 4 = 0
5 : mod 4 = 1
6 : mod 4 = 2
7 : mod 4 = 3
8 : mod 4 = 0
9 : mod 4 = 1
10 : mod 4 = 2
11 : mod 4 = 3
12 : mod 4 = 0

13 : mod 4 = 1

 

EDIT: cyberRobot beat me to it (because he took the easy route :) ), but I wanted to hopefully teach you how to solve problems like this in the future.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.