Should I really care if I am using
i += 1 in a loop?
Short answer is that there is no difference. Continue reading for the long answer.
So, again, what is the difference between these statements?
Let us use dnSpy and dissassembly to look at the facts.
i++. In dnSpy this generates following Common Intermediate Language (CIL):
Looking at the dissassembly this gives:
mov eax,dword ptr [rbp+2Ch]
mov dword ptr [rbp+2Ch],eax
++i. In dnSpy this generates following identical CIL:
with identical assembly code:
mov eax,dword ptr [rbp+28h]
mov dword ptr [rbp+28h],eax
Same thing for
i += 1 - CIL:
mov eax,dword ptr [rbp+24h]
mov dword ptr [rbp+24h],eax
So what does this give us in a loop:
for (i = 0; i < 100; i++)
k += i;
This results in following assembly (for all 3 cases):
jl Increment.Program.Main(System.String) + 010h(07FFADDF734D0h)
Conclusion: No matter what your mama says, there is no practical difference between i++, ++i or i += 1.
Just use the one you like best...