Get in touch with us! We’re here to assist you. Please fill out the form below, and we’ll respond to your inquiry as soon as possible.

If / Else

Solidity-ն աջակցում է պայմանական դրույթներին՝ if, else if և else:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

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;

        // if / else հայտարարությունը գրելու սղագրություն
        // «?" օպերատորը կոչվում է եռակի օպերատոր
        return _x < 10 ? 1 : 2;
    }
}

Փորձեք Remix-ում

What are your feelings