Assembly Conditional Statements

# Assembly Conditional Statements

Exemplo de declarações condicionais em assembly

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

contract AssemblyIf {
    function yul_if(uint x) public pure returns (uint z) {
        assembly {
            // if condition = 1 { code }
            // no else
            // if 0 { z := 99 }
            // if 1 { z := 99 }
            if lt(x, 10) { z := 99 }
        }
    }
    
    function yul_switch(uint x) public pure returns (uint z) {
        assembly {
            switch x
            case 1 {
                z := 10
            }
            case 2 {
                z := 20
            }
            default {
                z := 0
            }
        }
    }
}

# Teste no Remix

Last Updated: 22/01/2024 22:26:13