I was wondering about this pre-mature and not-too-important thing. I have written:
m_playerIndex = ++m_playerIndex % 2 // always either 0 or 1 (int)
for my chess game to make sure the other player will do the next move after the move that just has been done. However it's not quite readable, is it?
On top of that, it's incrementing a variable by 1, then calling the module operator of 2 on the adapted variable, meaning I have this temporary variable, which I assign to m_playerIndex and immediately after have it replaced by the result of %2. What would be the most efficient? Is it option 2, 1, or is there no difference at all? (I don't have programs to check those things yet.)
1)
m_playerIndex = ++m_playerIndex % 2
2)
m_playerIndex = (m_playerIndex + 1) % 2