Skip to content

Instantly share code, notes, and snippets.

@KiselevMaxim
Created November 14, 2021 14:26
Show Gist options
  • Save KiselevMaxim/61c513097c4b70943577876cdaee5cb3 to your computer and use it in GitHub Desktop.
Save KiselevMaxim/61c513097c4b70943577876cdaee5cb3 to your computer and use it in GitHub Desktop.
// 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