-
-
Save nomissbowling/5eedb3b7cc5fbb1f1d9b733ef46a9b56 to your computer and use it in GitHub Desktop.
Rust if文
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let x = 5; | |
//if(x == 5) { //←こうも書けるが、コンパイル時に警告が出る | |
if x == 5 { | |
println!("x is 5"); | |
} else { | |
println!("x isn't 5"); | |
} | |
//ifは式だからこんなこともできる。(三項演算子はない) | |
let y = if x == 5 { | |
10 | |
} else { | |
15 | |
}; //y == 10 | |
//let y = if x == 5 { 10 } else { 15 }; //←こんな感じで書くのが一般的 | |
println!("y is {}", y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment