Skip to content

Instantly share code, notes, and snippets.

@shootacean
Last active August 20, 2019 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shootacean/0907b8613b4b164f8196599ee871c564 to your computer and use it in GitHub Desktop.
Save shootacean/0907b8613b4b164f8196599ee871c564 to your computer and use it in GitHub Desktop.
Rust 練習用
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