0

As soon as I upgraded the code from solidity version 0.5.2 to 0.5.3, it showing warning in my for loop.

Warning: Unreachable code.
for(uint256 i=0; i < totalHoldTransactions; i++ ){
                                            ^-^

This SO article which gives idea in other programming languages. But I am still not sure why that increment variable is unreachable!

Any ideas will be appreciated. Thanks.

  • Maybe your totalHoldTransactions is 0 (or left uninitialized)? Anyway, it would help if you post more of your code. – Lauri Peltonen Jan 23 at 13:22
  • Thanks Lauri.. It should work even that is zero.. only issue was the return statement which cased loop to bounce.. and make increment variable to be unreachable.. – Yogesh - EtherAuthority.io Jan 23 at 13:25
0

After lots of research the culprit was the return statement inside the loop. So to anyone has this issue, you need to move any code outside of the for loop which causes it to bounce.

 for(uint256 i=0; i < totalHoldTransactions; i++ ){
       //other code..
       if(i >= 10){ break; }

       return true;  //this was the issue. I moved it to outside of loop and everything worked!!

    }
  • The problem that I see is that apparently the compiler is right. How should you reach that i++? – Rick Park Jan 23 at 22:10
  • Yes @Rick.. You are right.. I was making Silly mistake ;) – Yogesh - EtherAuthority.io Jan 24 at 1:13

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.