1. require:
- a validator function which takes two parameter, 1st the condn and second is the msg to display if error occurs
- e.g
function divide(uint _numberOne, uint _numberTwo) public returns (uint) {
require(_numberOne && numberTwo > 0, "number should be greater than 0");
return _numberOne / _numberTwo;
}
2. for loop:
- simple iterative loop
- e.g.
function sum(uint[] _nums) public returns (uint){
uint ans = 0;
for(uint i = 0; i < _nums.length; i++){
ans += _nums[i]
}
return ans;
}
3. If-else:
function checkEven(uint _num) public returns (bool){
if(_num % 2 == 0){
return true;
} else {
return false;
}
}