2024-03-20 09:31:14 +00:00
|
|
|
# Dust
|
|
|
|
|
|
|
|
High-level programming language with effortless concurrency, automatic memory management, type
|
2024-07-15 20:42:49 +00:00
|
|
|
safety and familiar syntax.
|
2024-03-20 09:31:14 +00:00
|
|
|
|
2024-05-18 15:59:39 +00:00
|
|
|
```dust
|
|
|
|
io.write_line("Guess the number.")
|
|
|
|
|
2024-07-28 16:52:07 +00:00
|
|
|
secret_number = random.in_range(0..100)
|
2024-05-18 15:59:39 +00:00
|
|
|
|
|
|
|
loop {
|
|
|
|
io.write_line("Input your guess.")
|
|
|
|
|
2024-07-28 16:52:07 +00:00
|
|
|
input = io.read_line().expect("Failed to read line.")
|
|
|
|
guess = match input.trim().parse() {
|
|
|
|
Ok(value) => value,
|
|
|
|
Err(_) => continue,
|
|
|
|
}
|
2024-05-18 15:59:39 +00:00
|
|
|
|
|
|
|
if guess < secret_number {
|
|
|
|
io.write_line("Too low!")
|
|
|
|
} else if guess > secret_number {
|
|
|
|
io.write_line("Too high!")
|
|
|
|
} else {
|
|
|
|
io.write_line("You win!")
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|