Last active
August 20, 2019 14:24
-
-
Save shootacean/0907b8613b4b164f8196599ee871c564 to your computer and use it in GitHub Desktop.
Rust 練習用
This file contains 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
use std::io::{self}; | |
fn main() { | |
hello(); | |
loop_for(); | |
loop_if(); | |
} | |
fn read_line() -> String { | |
let mut s = String::new(); | |
io::stdin().read_line(&mut s).unwrap(); | |
return s.trim_right().to_owned(); | |
} | |
fn hello() { | |
println!("Hello, World!"); | |
} | |
fn loop_for() { | |
for i in 0..10 { | |
println!("{}", i); | |
} | |
} | |
fn loop_if() { | |
for i in 0..10 { | |
let s: String; | |
if is_even(i) { | |
s = format!("even: {}", i); | |
} else { | |
s = format!("odd: {}", i); | |
} | |
println!("{}", s); | |
} | |
} | |
fn is_even(n: i32) -> bool { | |
return n % 2 == 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment