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);
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

GIve the syntax of a while loop

A

let mut x = 10;
while statement {
//come code here
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Give an example of a loop statement

A

let mut x = 10;
loop {

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly