0

Say we have a contract with a dynamic state array fooArray of uint256. At the same contract there is a function with the following loop:

for (uint256 i = 0; i < fooArray.length; ++i) {
// Some code here, that does not modify array in any way.
}

Does checking the loop condition require reading the length of the fooArray from the storage on each iteration or it is not considered as reading a value from the storage?
Should I preliminarily save length of the array to a local variable and use this variable as a loop condition to save gas?

1
  • 1
    Answered on StackOverflow by Peteris
    – ktv6
    Sep 24 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.