Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust 中消失的三元去了哪里? #327

Open
xxleyi opened this issue Nov 30, 2021 · 0 comments
Open

rust 中消失的三元去了哪里? #327

xxleyi opened this issue Nov 30, 2021 · 0 comments

Comments

@xxleyi
Copy link
Owner

xxleyi commented Nov 30, 2021

Just show code:

fn main() {
    nested_if_else_expresstion();
    refactor();
}

fn nested_if_else_expresstion() {
    let condition = true;

    let res = if condition {
        if condition == false {
            println!("33");
            33
        } else {
            println!("55");
            55
        }
    } else {
        println!("44");
        44
    };

    println!("{}", res)
}

fn refactor() {
    let condition = true;

    let res: i32;
    if condition {
        if condition == false {
            println!("33");
            res = 33;
        } else {
            println!("55");
            res = 55;
        }
    } else {
        println!("44");
        res = 44;
    }

    println!("{}", res)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant