Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Non-circular iterators

  • TODO
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