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,569
  • 2
  • 16
  • 24

1 Answers1

1

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

i = (i >= 8 ? 1 : ++i);
Anthony L
  • 1,995
  • 11
  • 24