-2

I have an infinite loop, and would like to add an if...else loop that triggers when the loop is at the 10th, 20th, 30th, (aka a multiple of 10) time.

I'd like to know whether it's possible to make something like

if (x is the multiple of 10) printf(something)

else printf(something else)

Thanks!

Dummie1138
  • 61
  • 1
  • 7
  • Possible duplicate of [Python remainder operator](https://stackoverflow.com/questions/18499458/python-remainder-operator) – George Oct 12 '19 at 22:10
  • If it's an infinite loop, when an (unsigned) counter wraps you'll get a discontinuity. Just count to 10 and reset the counter. – Weather Vane Oct 12 '19 at 22:33

1 Answers1

1

A number is a multiple of 10 if its remainder when dividing by 10 is 0. So use the modulus operator %:

if (x % 10 == 0) {
    // do something
} else {
    // do something else
}
dbush
  • 205,898
  • 23
  • 218
  • 273