What i want my code to do
Everytime the function is called the exampleValue of all users should be increased by 5
What the code actually does
When i compile it in Remix i get this error message:
TypeError: Integer constant expected. User[i].value = User[i] + 5; ^
Code
pragma solidity 0.6.0;
contract LoopingThroughArray {
struct User {
uint256 exampleValue;
address id;
}
User[] public users;
receive() external payable {
for (uint i=0; i<=users.length; i++) {
User[i].exampleValue = User[i] + 5; // thats the line where i get the error
}
}
}
What i already tried
- replacing the users.length with a constant uint both in- and outside of the function
- using a normal function instead of the receive function