...by Daniel Szego
quote
"On a long enough timeline we will all become Satoshi Nakamoto.."
Daniel Szego

Tuesday, April 3, 2018

Solidity Tips and Tricks - var as type declaration


Although there is a possibility to use var at a variable declaration, meaning that the variable is initialized by the first declaration automatically, you should have extreme caution using this pattern. As an example, using for instance var i = 0; initializes the variable automatically as uint8 implying that the following loop is an infinite one causing an out of gas exception in solidity.  

contract TestContract {
  function infiniteLoop() {
    for (var i = 0; i < 1000; i++) {
    ...
    }
  }
}