Mod ("modulo") is good for cylic things. I used them in the exit generation and navigation code I posted for imamy. To refresh a bit, the mod function to a base returns a number which is (naïvely) the remainder when divided by that base. That definition isn't 100% accurate, but it works for positive numbers, and it might be easier to understand if the concept is new. Here is the first set of numbers mod 4:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14...
0 1 2 3 0 1 2 3 0 1 2 3 0 1 2...
As you can see, the mod function repeats. You can talk about two numbers being "equivalent mod X" if they have the same value mod X. For example, 3, 7 and 11 are all equivalent mod 4.
Let's say you have a rotation attribute with these values:
North = 0
East = 1
South = 2
West = 3
where each succeeding number goes 90 degrees further right. This allows you to have a single "direction" index. So how do you rotate right? Generally, you add 1 to the direction index. So North (0) goes to East (1) goes to South (2), etc. And to rotate left, you'd subtract 1.
When you get to the ends, though, you need to wrap. Now, you can put "if"s in saying "Add 1. If the new value is 4 set it to 0" and similarly for left rots. It's easier just to use:
dir = (dir + 1) % 4
The problem comes in with negative numbers. If you look at the above pattern for 0-14, you'll see a pattern of 0,1,2,3, repeating over and over. A technically correct mod preserves that going further negative, so that -1 would be 3, -2 would be 2, -3 would be 1, and -4 would be zero again:
-7 -6 -5 -4 -3 -2 -1 0 1 2 3 4
1 2 3 0 1 2 3 0 1 2 3 0
The mod n values are always [0..n-1]. However, some implementations seem to do it strictly as if it were a remainder, such that -1 mod 4 would be -1, -2 would be -2, etc
-7 -6 -5 -4 -3 -2 -1 0 1 2 3 4
-3 -2 -1 0 -3 -2 -1 0 1 2 3 0
And this causes problems! Because now in our case, if we go left from 0, we end up at -1, not 3. There are ways around this. For example, we can do this:
Right:
dir = (dir + 1) % 4
Left:
dir = (dir + 3) % 4
and that will always work. (It might seem off, but think: if we add 4, we're back to the same number, mod 4. So adding 3 gets us to the number just left of it. The number 3 is the equivalent of -1.)
I don't know if that answers it all (or too much), but it's one use for mod. You see things like mod all the time - time on a clock (which is mod 12 hours), degrees in a circle (which are mod 360), etc.
Edit: fixed the directions above.