2

I am writing a code to return multiple values from two arrays simultaneously. I understand since I mentioned only one uint and one address as arguments in returns, the for loop is throwing an error. What can I do to be able to return multiple values from both the arrays? Following is my code snippet:

function listBest() public view returns(uint, address){
    for(uint p = 0; p < number; p++) {
        return(listScores, listScoredPeople[p]);
    }
}
2
2

You can return multiple values, as per Destructuring Assignments and Returning Multiple Values.

But your current code is going to return on the first iteration of the loop.

You could either:

  • Create and return two arrays
  • Define a struct that contains one member of each array, then return an array of the structs.

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.