
Originally Posted by
jhildy
ok when you use the mathematical function mod is this what it does
it takes the first number and calculates how far away from the closes multiple of the last number.
for example
this would be 1 because 4 is one away from the closest multiple of 6 which is 3
i dont know if this is correct but it seems the most logical.
Nope, here is what the mod function does.
It takes the first number, divedes it by the second, and return the remainder.
for example, 4 mod 6 means
4 divided by 6, = 0, with a remainder of 4
so the answer is 4
another?
8 mod 2
8 divided by 2 is 4, with a remainder of 0
so the answer is 0
I normaly use mods when I have a repeat, but I want to do something every X times it repeats.
Check this out
SCAR Code:
program New;
var repeats:Integer;
const howOften=4;
begin
repeats:=0;
repeat
writeln(inttostr(repeats)+' mod ' + inttostr(howOften) + ' is ' + inttostr((repeats mod howOften)));
if ((repeats mod howOften)=0) then //the "0" could be any number, depending on when u want the first true
writeln('Time for a special thing to happen!!');
repeats:=repeats+1;
until(repeats>15);
end.
0 mod 4 is 0
Time for a special thing to happen!!
1 mod 4 is 1
2 mod 4 is 2
3 mod 4 is 3
4 mod 4 is 0
Time for a special thing to happen!!
5 mod 4 is 1
6 mod 4 is 2
7 mod 4 is 3
8 mod 4 is 0
Time for a special thing to happen!!
9 mod 4 is 1
10 mod 4 is 2
11 mod 4 is 3
12 mod 4 is 0
Time for a special thing to happen!!
13 mod 4 is 1
14 mod 4 is 2
15 mod 4 is 3
Successfully executed
[IMG]http://farm3.static.flickr.com/2120/2052732965_348f3629d0_o.jpg[/IMG]