Skip to main content

Is it possible to return multiple values inside a for cycle? I mean, without knowing the number of output (it will be dynamically increased every time an array will be filled), is it possible to represent every element of that array as output of a function?

Something like this

function getList() view public returns (string, address) {

function getList() view public returns (string, address) {

    for (uint i = 0; i < arrayOfStringValues.length; i++){

        return (arrayOfStringValues[i], arrayOfAddressValues[i]);}
}

}

I tried to do this, but the function returns only the first "couple".

Is it possible to return multiple values inside a for cycle? I mean, without knowing the number of output (it will be dynamically increased every time an array will be filled), is it possible to represent every element of that array as output of a function?

Something like this

function getList() view public returns (string, address) {

for (uint i = 0; i < arrayOfStringValues.length; i++){

    return (arrayOfStringValues[i], arrayOfAddressValues[i]);}

}

I tried to do this, but the function returns only the first "couple".

Is it possible to return multiple values inside a for cycle? I mean, without knowing the number of output (it will be dynamically increased every time an array will be filled), is it possible to represent every element of that array as output of a function?

Something like this

function getList() view public returns (string, address) {

    for (uint i = 0; i < arrayOfStringValues.length; i++){

        return (arrayOfStringValues[i], arrayOfAddressValues[i]);}
}

I tried to do this, but the function returns only the first "couple".

Source Link
Bruce Wayne
  • 385
  • 3
  • 13

Solidity: return values in for cycle

Is it possible to return multiple values inside a for cycle? I mean, without knowing the number of output (it will be dynamically increased every time an array will be filled), is it possible to represent every element of that array as output of a function?

Something like this

function getList() view public returns (string, address) {

for (uint i = 0; i < arrayOfStringValues.length; i++){

    return (arrayOfStringValues[i], arrayOfAddressValues[i]);}

}

I tried to do this, but the function returns only the first "couple".