Looping through array vs. resetting array #449
-
In Lesson 4, Basic Solidity: For Loop and Resetting An Array (at around approx 4:40:00), Patrick shows us how to first loop through an array to reset all the values we had previously set to 0. And then after the for loop, he shows us how to reset an array by redeclaring it as empty. In real world, do you really need that loop or wouldn't you just reset the array? for (uint256 funderIndex = 0; funderIndex < funders.length; funderIndex=funderIndex + 1){
address funder = funders[funderIndex];
addressToAmountFunded[funder] = 0;
}
//reset the array
funders = new address[](0); // new array with 0 objects // WHY IS THE LOOP NEEDED IF WE ARE DOING THIS? |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
Jun 20, 2022
Replies: 1 comment 1 reply
-
Patric used for loop for resetting the mapping's each address value to 0. And after for loop, he reset the Array. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
PatrickAlphaC
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@atenger
Patric used for loop for resetting the mapping's each address value to 0. And after for loop, he reset the Array.