Skip to content
New issue

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

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

Already on GitHub? # to your account

T1: In rust must end with a semicolon? #6

Open
yangwenmai opened this issue Apr 23, 2019 · 0 comments
Open

T1: In rust must end with a semicolon? #6

yangwenmai opened this issue Apr 23, 2019 · 0 comments
Labels
tips some tips

Comments

@yangwenmai
Copy link
Owner

yangwenmai commented Apr 23, 2019

在 Rust 中必须以分号结束?

fn main() {
    let f = false;
}

fn main() {
    let f = false
    let f: bool = true;
}

但是,如果你的语句是函数体的最后一行,可以省略分号。

fn main() {
    let f = false;
    let f: bool = true;
    println!("f is: {}, f2 is: {}", f, f2)
}

fn main() {
    let f = false;
    let f: bool = true;
    t()
}

fn t() {
    let f = false;
    let f: bool = true
    println!("f is: {}, f2 is: {}", f, f2)
}

表达式的结尾没有分号。如果在表达式的结尾加上分号,它就变成了语句,而语句不会返回值。

@yangwenmai yangwenmai added the tips some tips label Apr 23, 2019
@yangwenmai yangwenmai changed the title T1: In rust must end with a semicolon T1: In rust must end with a semicolon? Apr 23, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
tips some tips
Projects
None yet
Development

No branches or pull requests

1 participant