Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Solidity: An example implementation of why not to trust `var i = 0` in for loops
//sol Infinite8BitForLoop
// @authors
// Tim Cotten <tim@cotten.io> (https://blog.cotten.io)
// An example implementation of why not to trust `var i = 0` in for loops
// Input to the test function above 255 results in an infinite loop
pragma solidity ^0.4.0;
contract Infinite8BitForLoop {
function test(uint256 x) public pure returns(uint256)
{
uint256 total = 0;
for (var i = 0; i < x; i++) {
total++;
}
return total;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.