I'm aware of the fact that pure/view functions cost no gas with a simple "call".
But what happens if i have a function that changes the contract state based on the pure/view function result. Do i have to pay gas for the pure/view functions looping if i do a "send"?
In my example I want to find a number in an array and return the index.
function indexOfUint(uint256[] _array, uint _value) public pure returns (uint256) {
bool exist;
for (uint i=0; i<_array.length;i++){
if(_array[i] == _value){
exist = true;
return i;
}
}
assert(exist == true);
}
Best Answer
There are two statements in https://github.com/ethereum/solidity/issues/992
It means view and pure can't change state of contract. If you need to change state of contract you need to remove
pure
,view
keywords.The function does not change state of contract.
exist
variable stores in stack