0

Refer the fn below :

function _check() internal returns(bool success) {
        for (uint i = 0; i<registered.length; i++ ) {
            if(registered[i] == msg.sender) {
                return true;
            } else {
            return false;
            }
        }
        
     }

Remix is showing two warnings :

  1. Function state mutability can be restricted to view.
  2. Unreacheable code i++.

How can I silent the two? Is the function truly 'view' ?

Please help.

2

It is unreachable code it is not a warning it is a bug in your code? you are only checking the first element in the registered array and return directly false or true without looking at the rest of the array !!!! -__-

Yes it is view, View functions are functions which do not change the storage

function _check() internal view returns(bool success) {
    for (uint i = 0; i < registered.length - 1; i++) {
        if(registered[i] == msg.sender) {
            return true;
        }
    }
    return false;
 }

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.