Chez oim, forum libre

Débattre => Informatique, programmation, geek attitude... => Discussion démarrée par: Songbird le lundi 27 juin 2016, 14:54

Titre: Comment parcourir un tableau ?
Posté par: Songbird le lundi 27 juin 2016, 14:54
Implémentant le trait IntoInterator (https://doc.rust-lang.org/std/iter/trait.IntoIterator.html), nous pouvons utiliser la fonction iter() comme ceci:

Code
let my_array : [&str; 5] = ["one", "two", "three", "four", "five"];
for word in my_array.iter()
{
   println!("{}", word);
}

Résultat:
Code
one
two
three
four
five