0

I'm trying to make a function that includes a for loop and an if/if else statement and am running into errors. The syntax regarding where to put the brackets here confuses me.

function decider(nbaTeam[] memory team) public {
    for(uint i=0; i < 31; i++) {
    if (team[i].oRtg > avgOrtg && team[i].dRtg < avgDrtg) {
        niceTeams.push(team);
    }
    }   else if (team[i].oRtg <= avgOrtg && team[i].dRtg >= avgDrtg) {
        naughtyTeams.push(team);
    }
    }

"Expected primary expression." error on the else if statement line.

2
  • It would have been better if you can share a full code for proper understanding but you can just declare a return statement in your 'else' block code and omit the expression May 22, 2022 at 20:19
  • ok I will do that next time, thank you
    – gecko74
    May 23, 2022 at 18:09

1 Answer 1

0

If you indent the code properly you'll see that there's an extra } before the else if. In solidity braces are used to surround block of codes {}.

function decider(nbaTeam[] memory team) public {
    for (uint i=0; i < 31; i++) {
        if (team[i].oRtg > avgOrtg && team[i].dRtg < avgDrtg) {
            niceTeams.push(team);    
        } else if (team[i].oRtg <= avgOrtg && team[i].dRtg >= avgDrtg) {
            naughtyTeams.push(team);
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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