Code examples

List bus arrivals

Start at the first arrival and add the same number of minutes for each bus.

Simple example

Start0 → 2
Result0 1 2
main.rs
fn main() {
    let mut minute: i64 = 0;
    while minute <= 2 {
        println!("{}", minute);
        minute += 1;
    }
}
Output
0
1
2
Advertisements

Everyday examples

A bus arrives every 10 minutes. Starting at minute 0, show its first three arrival times.

Start0 → 20
Result0 10 20
main.rs
fn main() {
    let mut minute: i64 = 0;
    while minute <= 20 {
        println!("{}", minute);
        minute += 10;
    }
}
Output
0
10
20
Run the example
Terminal
rustc main.rs
./main
Official documentation