rust/tests/run-pass/rust-lang-org.rs
Oliver Schneider d6f1ba89ce
fix matching on chars
fixes #63
2016-09-27 11:10:25 +02:00

22 lines
548 B
Rust

// This code is editable and runnable!
fn main() {
// A simple integer calculator:
// `+` or `-` means add or subtract by 1
// `*` or `/` means multiply or divide by 2
let program = "+ + * - /";
let mut accumulator = 0;
for token in program.chars() {
match token {
'+' => accumulator += 1,
'-' => accumulator -= 1,
'*' => accumulator *= 2,
'/' => accumulator /= 2,
_ => { /* ignore everything else */ }
}
}
assert_eq!(accumulator, 1);
}