function simpleLoop() public view {
for(uint i=0; i<10;i++) {
console.log("Number ==",i);
}
}
function iPlus() public view {
for(uint i=0; i<10;) {
console.log("Number ==",i);
unchecked{
i++;
}
}
}
function Plusi() public view {
for(uint i=0; i<10;) {
console.log("Number ==",i);
unchecked{
++i;
}
}
}
iPlus
Plusi
console.log:
Number == 0
Number == 1
Number == 2
Number == 3
Number == 4
Number == 5
Number == 6
Number == 7
Number == 8
Number == 9
console.log:
Number == 0
Number == 1
Number == 2
Number == 3
Number == 4
Number == 5
Number == 6
Number == 7
Number == 8
Number == 9
simpleLoop
console.log:
Number == 0
Number == 1
Number == 2
Number == 3
Number == 4
Number == 5
Number == 6
Number == 7
Number == 8
Number == 9
i++ ⇨ doing 4 operations because of saving value of i for a memory ++i ⇨ doing 2 operations
https://www.reddit.com/r/ethdev/comments/tcwspw/i_vs_i_gas_efficiency/