Last active
February 3, 2022 20:07
-
-
Save raj-pranav/440ec3f10d1e7f11fb889757e7640106 to your computer and use it in GitHub Desktop.
control structure - if else
This file contains 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.6.0 <0.9.0; | |
contract demo_if { | |
uint x = 10; | |
function Compare (uint _x) external view returns (string memory){ | |
if (_x >= x) { // if section | |
return 'Given value is greater or equal to x';} | |
else { // else section | |
return 'Given value is less than x'; | |
} | |
} | |
} | |
This file contains 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
if (condition) { | |
body ;} | |
else if (another condition) { | |
body ; } | |
else { | |
body ; } |
This file contains 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.6.0 <0.9.0; | |
contract demo_if { | |
uint x; | |
function CompNum (uint _x) public view returns (string memory) { | |
if (_x > x) { | |
return 'The number entered is bigger'; | |
} else if (_x < x) { | |
return 'Number entered is lesser'; | |
} else { | |
return 'Both numbers are equal'; | |
} | |
} | |
} |
This file contains 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.6.0 <0.9.0; | |
contract demo_if2 { | |
function CompNum (uint _x) public pure returns (string memory) { | |
if (_x == 1) { | |
return 'Monday'; } | |
else if (_x == 2) { | |
return 'Tuesday';} | |
else if (_x == 3) { | |
return 'WednesDay';} | |
else if (_x == 4) { | |
return 'Thursay';} | |
else if (_x == 5) { | |
return 'Friday';} | |
else if ((_x == 6) || (_x == 7)) { | |
return 'It is a Weekend';} | |
else { | |
return 'Invalid Input'; | |
} | |
} | |
} |
This file contains 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.6.0 <0.9.0; | |
contract demo_if { | |
uint x = 10; | |
function Compare (uint _x) external view returns (bool){ | |
if (_x >= x) { // only one if statement | |
return true; | |
} | |
} | |
} | |
This file contains 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.6.0 <0.9.0; | |
contract demo_if { | |
uint x = 10; | |
function Compare (uint _x) external view returns (string memory){ | |
return _x >= x ? 'Given value is greater or equal to x' : 'Given value is less than x' ; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment