for (int i = 0; i < 100; i = (i%10))
{
age = (age +10);
int_year = (int_year + 10);
So I am trying to use the Mod function for looping in C#, the requirement is that it the int_year and age loop 100 times but only every 10th increment is kept. Thanks in advance :)
Why not just mod 10 within the loop to determine if this is the 10th iteration:
for (int i = 0; i < 100; i++)
{
if (i % 10 == 0)
{
// Every 10th iteration
}
}
You can use step equal to 10:
for (int i = 0; i < 100; i += 10)
{
// Every 10th iteration
}
I think it's more efficient than using mod.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With