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]);
    }
}
Franco Victorio
  • 2,862
  • 17
  • 27

1 Answers1

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.
Richard Horrocks
  • 37,835
  • 13
  • 87
  • 144