I am trying to display whenever I need to do a certain action in my for loop every 300th iteration (makes sense?)
Here is in code what I want to do, but not the way I want to do it:
for I := 0 to 2000 do
Begin
if I = 300 then
DoAnAction;
if I = 600 then
DoAnAction
if I = 900 then
DoAnAction
if I = 1200 ......... Same action all over, but I don't want to check all those conditions!
End;
So I have been told to use the mod operator, and this is how I do it:
for I := 0 to 2000 do
Begin
if I mod 300 = 299 then
DoAnAction;
End;
However, the results using the above snippet would do the action at 299, 599, 899 ….
How can I make it do it at 300, 600, 900 …… using the Mod operator? (And doing if I mod 300 = 300 did not work)
Thanks!
Though your previous version does makes sense too, I=299 is the 300th pass 😉
EDIT:
I mod 300 = 300would not work becausemodoperator returns the remainder of devision, which is by definition will be in range0..299