rustlings/src/about_variables.rs

40 lines
734 B
Rust
Raw Normal View History

use title;
use verify;
2018-05-06 10:27:03 -05:00
// Variables in Rust are defined using the "let" keyword. Like this:
fn exercise_one() {
let x = 5;
verify(5, x);
// ^ ^
// | |
// What's The variable
2018-05-22 14:24:43 -05:00
// in it name
2018-05-16 08:27:52 -05:00
}
// Try to replace the "0" with the value of the variable, then run
// "cargo run" and see if it was correct!
// Here's a more complicated example:
fn guess_me() -> &'static str {
let x = 10;
if x == 10 {
return "Ten!";
} else {
return "Not ten!";
}
}
fn exercise_two() {
let result = guess_me();
verify("REPLACE ME", result);
}
2018-05-14 11:41:58 -05:00
2018-05-16 08:30:30 -05:00
pub fn exec() {
title("Variables: Exercise 1");
exercise_one();
title("Variables: Exercise 2");
exercise_two();
2018-05-14 11:41:58 -05:00
}