0

I am new to solidity and stucked at very strange issue. I am not able to use variable i for any type of operation inside for loop.

for (uint256 i; i < data.numPoints; i++) {
        //uint256 xx = data.x; //Working
        //uint256 yy = data.y; //Working
        //uint256 xx = data.x * i; //Not working
        //uint256 yy = data.y * i; //Not working
        uint256 xx = i; //Not working
        uint256 yy = i; //Not working
        points[i] = xx;
    }

Contract get compile successfully but throw run time exception on call. Am I missing something??

1
  • are u missing uint256 i=0; ?
    – Majd TL
    Commented Aug 23, 2021 at 17:45

1 Answer 1

0

You haven't provided enough information to replicate your issue or comment on your troubleshooting process.

It's not clear how you reached the conclusions you reached.

The line that is most suspect is the line that is not commented at all.

points[i] = xx;

If i >= points.length then this line will revert because you cannot write to an array member that doesn't exist. You can't append to an array this way.

Also, in the case that this line reverts, all previous lines will also revert because transaction execution is atomic. That can lead to confusing results using normal troubleshooting thinking.

In any case, it's impossible to say if that's the issue but it's a common issue and the other stuff appears to be low-risk.

Hope it helps.

1
  • 1
    Thank you for the response. and yes you are right it was array length issue.
    – Sama
    Commented Aug 23, 2021 at 19:02

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.