Skip to content

Latest commit

 

History

History
27 lines (21 loc) · 400 Bytes

loop.md

File metadata and controls

27 lines (21 loc) · 400 Bytes

循环语法

首先是for循环,格式为for xx in xx {},continue:跳过当次循环,break:跳出整个循环

for i in 1..5 { // 1..5 生成1到5,不包含5的数组
    println!("{}",i)
}

while循环

let mut n = 0;
while n <= 5{
    println!("{}", n);
    n = n + 1;
}

loop循环,直接无限循环

loop {
    println!("loop")
}