Operations such as state variable updates (use SSTORE
s) inside a loop cost a lot of gas, are expensive and may lead to out-of-gas errors. Optimizations using local variables are preferred. (see here)
- Costly Operations Inside Loops
- State Variable Updates
- Out-of-Gas Error
- Use Local Variables Prevent DoS