BlockChain,NFT,Web3.0/Solidity
solidity 08. 선택문 (조건문)
일등하이
2022. 1. 15. 03:24
반응형
프로그램을 작성하는 동안 주어진 경로 집합 중 하나를 채택해야 하는 상황이 발생할 수 있다
이러한 경우 프로그램이 올바른 결정을 내리고 올바른 작업을 수행할 수 있는 조건부 문을 사용한다
if문
if-else 문
if-else if문
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract IfElse {
function foo(uint x) public pure returns (uint) {
if (x < 10) {
return 0;
} else if (x < 20) {
return 1;
} else {
return 2;
}
}
function ternary(uint _x) public pure returns (uint) {
// if (_x < 10) {
// return 1;
// }
// return 2;
// shorthand way to write if / else statement
return _x < 10 ? 1 : 2;
}
}
참고
https://solidity-by-example.org/if-else/
https://solidity-by-example.org/if
https://docs.soliditylang.org/en/v0.8.11/
https://www.geeksforgeeks.org/solidity-operators/?ref=lbp
https://www.tutorialspoint.com/solidity/solidity_decision_making.htm
https://www.youtube.com/watch?v=jPHXG82WCYA&list=PLbbtODcOYIoE0D6fschNU4rqtGFRpk3ea&index=5
반응형