Non-circular iterators



examples/iterators/non-circular-iterator/src/main.rs
fn main() {
    let animals = [
        String::from("cat"),
        String::from("dog"),
        String::from("crab"),
    ];

    let mut iterator = animals.iter();
    loop {
        if let Some(animal) = iterator.next() {
            println!("{animal}")
        } else {
            println!("No more animals");
            break;
        }
    }

    if let Some(animal) = iterator.next() {
        println!("{animal}")
    } else {
        println!("This iterator is finished");
    }
}

cat
dog
crab
No more animals
This iterator is finished