0

Can someone explain to me why this statement won't work?

i = (i >= 8 ? 1 : i++);

yet this one does?

i = (i >= 8 ? 1 : (i + 1));

Thomas Valadez
  • 1,697
  • 2
  • 22
  • 27

1 Answers1

1

As Raymond mentioned, you're using postincrement, you should use preincrement in this context:

i = (i >= 8 ? 1 : ++i);
Anthony L
  • 2,159
  • 13
  • 25