Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUST

Pushing Array values to a Vector in Rust

fn main() {
    let presents = [
        "A song and a Christmas tree",
        "Two candy canes",
        "Three boughs of holly",
    ];

    let mut current_presents = Vec::new();

    for (day, present) in presents.iter().enumerate() {
        current_presents.push(present);
        println!(
            "On the {} day of Christmas my good friends brought to me",
            day
        );
        println!("{current_presents:?}
");
    }
}
 
PREVIOUS NEXT
Tagged: #Pushing #Array #values #Vector #Rust
ADD COMMENT
Topic
Name
4+6 =