If possible, use prefix increment instead of postfix increment
Prefix increment ++i returns the updated value after it's incremented and postfix increment i++ returns the original value then increments it. Prefix increment costs less gas compared to postfix increment.
It is recommended to use prefix increment instead of postfix one when the return value is not needed, as both of them will give the same result and prefix increment costs less gas.
If possible, use prefix increment instead of postfix increment
Prefix increment
++i
returns the updated value after it's incremented and postfix incrementi++
returns the original value then increments it. Prefix increment costs less gas compared to postfix increment.Instances includes :
Recommendation
It is recommended to use prefix increment instead of postfix one when the return value is not needed, as both of them will give the same result and prefix increment costs less gas.
For example :