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

Why?

  1. unchecked means don’t use default underflow/overflow checks(this checks start from the version of 0.8.0)
  2. the difference between ++i and i++

i++ ⇨ doing 4 operations because of saving value of i for a memory ++i ⇨ doing 2 operations

Resources

https://www.reddit.com/r/ethdev/comments/tcwspw/i_vs_i_gas_efficiency/

https://moralis.io/gas-optimizations-in-solidity-top-tips/