1
0
dust/examples/guessing_game.ds

27 lines
541 B
Plaintext
Raw Normal View History

# This is a Dust version of an example from the Rust Book.
#
# https://doc.rust-lang.org/book/ch02-00-guessing-game-tutorial.html
output("Guess the number.")
2024-02-20 02:17:28 +00:00
secret_number = int:random_range(0..=100)
loop {
output("Please input your guess.")
2024-02-19 20:24:44 +00:00
input = io:stdin():expect("Failed to read line.")
2024-02-20 02:17:28 +00:00
guess = int:parse(input)
output("You guessed: " + guess)
match cmp(guess, secret_number) {
2024-02-20 02:17:28 +00:00
Ordering::Less -> output("Too small!")
Ordering::Greater -> output("Too big!")
Ordering::Equal -> {
2024-02-20 02:17:28 +00:00
output("You win!")
break
}
}
2024-02-19 20:24:44 +00:00
}