rust 个例
作者:互联网
fn main() {
let a = [4,3,2,1];
// 通过索引和值的方式迭代数组 `a`
for (i,v) in a.iter().enumerate() {
println!("第{}个元素是{}",i+1,v);
}
}
================================================================
fn main() {
let names = [String::from("liming"),String::from("hanmeimei")];
for _name in &names {
// do something with name...
}
println!("{:?}", names);
let numbers = [1, 2, 3];
// numbers中的元素实现了 Copy,因此无需转移所有权
for _n in numbers {
// do something with name...
}
println!("{:?}", numbers);
}
标签:...,name,let,numbers,个例,println,rust,names 来源: https://www.cnblogs.com/pythonClub/p/16461663.html