It is not necessarily obvious what is happening here, is there a more elegant way to do this?
Although this is not immediately obvious to some, I know for sure what it does.
However, what you might want to consider is that it is more important to write readable code than to be smart. The code must be saved and you are NOT smarter than the compiler.
Write the code this way, and be happy with it:
The important point is that this code is now readable and still optimized. It does exactly what other code does, and we can swap parts later without re-reading the code.
Also pay attention to some semantics that I used here.
- Always use braces, even if you donβt think you need them.
- Make
CurrentQuestion = CurrentQuestion + 1; instead of CurrentQuestion += 1; or CurrentQuestion++; or ++CurrentQuestion; , because the first is much more explicit in intention. Always write intentional code.
source share