Do I need to explicitly initialize the 'i' variable in a for loop? Since i
is a uint
and its default value is 0
, why should I spend gas in a MSTORE operation to initialize the variable with 0
? The same question applies to result
.
function sum10() external pure returns (uint256) {
uint256 result;
for(uint256 i; i< 10; i++){
result += i;
}
return result;
}