Loops Flashcards

1
Q

What is the recipe for a while loop in R?

A

while (cond) {
expression
}

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

What statement exits a while or for loop?

A

break

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

What statement skips the current iteration of a while or for loop?

A

next

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

What is the recipe to loop over a vector or list in R using a for loop?

A

for (item in my_vector_or_list) {
expression
}

OR

for (i in 1:length(my_vector_or_list)) {
expression
}

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

What is the recipe to loop over a matrix in R using two for loops?

A

for (i in 1:nrow(my_matrix)) {
for (j in 1:ncol(my_matrix)) {
expression
}
}

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