Recall & Review
beginner
What does the
next statement do in R loops?The
next statement skips the current iteration of a loop and moves to the next iteration immediately.Click to reveal answer
beginner
What is the purpose of the
break statement in R?The
break statement stops the entire loop immediately and exits it.Click to reveal answer
beginner
How does
next differ from break in R loops?next skips only the current loop iteration and continues with the next one, while break stops the loop completely.Click to reveal answer
beginner
Example: What will this R code print?<br>
for(i in 1:5) { if(i == 3) next; print(i) }It will print 1, 2, 4, 5 each on a new line. When
i is 3, next skips printing 3.Click to reveal answer
beginner
Example: What will this R code print?<br>
for(i in 1:5) { if(i == 3) break; print(i) }It will print 1 and 2 each on a new line. When
i is 3, break stops the loop immediately.Click to reveal answer
What happens when
next is executed inside a loop in R?✗ Incorrect
next skips the rest of the current iteration and moves to the next iteration.What does the
break statement do in an R loop?✗ Incorrect
break immediately exits the loop, stopping all further iterations.In which situation would you use
next instead of break?✗ Incorrect
next skips only the current iteration and continues the loop.What will this code print?<br>
for(i in 1:4) { if(i == 2) break; print(i) }✗ Incorrect
When
i is 2, break stops the loop, so only 1 is printed.What will this code print?<br>
for(i in 1:4) { if(i == 2) next; print(i) }✗ Incorrect
When
i is 2, next skips printing 2, so 1, 3, and 4 are printed.Explain the difference between
next and break statements in R loops.Think about what happens to the loop after each statement.
You got /3 concepts.
Describe a real-life example where you might use
next in a loop.Imagine you are sorting items and want to ignore some but keep going.
You got /3 concepts.