Rust - Loop Flashcards
1
Q
Create an example of a for loop that iterates from 1 to 10 which skips the number 5
A
fn main(){
for x in 1..11{ // 11 is not inclusive
if x==5 {
continue;
}
println!(“x is {}”,x);
}
}
2
Q
GIve the syntax of a while loop
A
let mut x = 10;
while statement {
//come code here
}
3
Q
Give an example of a loop statement
A
let mut x = 10;
loop {
}
4
Q
A