Created
November 14, 2021 14:26
-
-
Save KiselevMaxim/61c513097c4b70943577876cdaee5cb3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity >=0.7.0 <0.9.0; | |
/** | |
* @title IF ELSE approach or IF IF approach | |
* @dev return value with different approaches | |
* @dev compiled solidity 0.8.10 optimization 200 | |
*/ | |
contract IF_ELSE { | |
uint256 number; | |
function getIFIF(uint256 parameter) public view returns (uint256 result) { | |
if(parameter == 1) { | |
result = parameter; | |
} // 21516 gas | |
if(parameter == 2) { | |
result = parameter; | |
} // 21516 gas | |
} | |
function getIFELSE(uint256 parameter) public view returns (uint256 result) { | |
if(parameter == 1) { | |
result = parameter; // 21503 gas | |
} else { | |
result = parameter; // 21504 gas | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment