I would like to write a for loop like this:
for (uint256 i = 0; i < length; unchecked { i += 1 }) {
// ...
}
But unfortunately this does not compile (fails with an error "expected primary expression").
How can I write an unchecked for loop? That is, I would like to use unchecked arithmetic only to increment the index i
- not for any other operation in the body of the loop.