Solidity-033 IfElse

// SPDX-License-Identifier: MIT

// Version of the Solidity compiler to be used for compilation

pragma solidity ^0.8.9;

// Contract definition for IfElseExample

contract IfElseExample {

    // Enumerated type to represent different request states

    enum requestState {

        created,    // Request state: Created

        approved,   // Request state: Approved

        provisioned,// Request state: Provisioned

        rejected,   // Request state: Rejected

        deleted,    // Request state: Deleted

        none        // Request state: None (default)

    }

    /**

     * @dev Function for state management based on the provided state value.

     * @param _state The integer value representing a request state.

     * @return result An integer result indicating the outcome of state management:

     *               - 1 if the provided state is equal to 'created'.

     *               - 2 if the provided state is equal to 'approved' or 'provisioned'.

     *               - 3 if the provided state is none of the above, or if it's set to 'none'.

     */

    function StateManagement(uint8 _state) public returns (int result) {

        // Convert the provided integer state value to the requestState enum

        requestState currentState = requestState(_state);

        // Check if the currentState is equal to 'created' (requestState 1)

        if (currentState == requestState(1)) {

            result = 1; // Set the result to 1

        }

        // Check if the currentState is equal to 'approved' or 'provisioned'

        else if ((currentState == requestState.approved) || (currentState == requestState.provisioned)) {

            result = 2; // Set the result to 2

        }

        // Handle all other cases, including 'rejected', 'deleted', and 'none'

        else {

            currentState == requestState.none; // Set currentState to 'none' (default)

            result = 3; // Set the result to 3

        }

    }

}

//Deploy:

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值