Using For Solidity

[Solved] Using For Solidity | Solidity - Code Explorer | yomemimo.com
Question : using for solidity

Answered by : sheeeev66

// `for` is used to attach functions to variable types.
// Example:
function sum(uint a, uint b) returns(uint) { return a + b;
}
using sum for uint;
// then you can use this inside your contracts:
contract MyContract { function add1(uint num) public pure returns(uint) { return num.sum(1); // `num` is passed as the first parameter (`a`) and `1` as the second (`b`) }
}
// You can also use libraries this way:
library Math { function sum(uint a, uint b) returns(uint) { return a + b; } function sub1(uint x) returns(uint) { return(x - 1); }
}
contract MyContract { using Math for uint; function uselessCalculation(uint x, uint y) returns(uint) {	return x.sum(y).sub1(); }
}

Source : | Last Update : Tue, 17 May 22

Answers related to using for solidity

Code Explorer Popular Question For Solidity