Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to skip the current iteration when x equals 3.
R Programming
for (x in 1:5) { if (x == 3) { [1] } print(x) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'break' instead of 'next' will stop the entire loop.
✗ Incorrect
In R, next skips the current loop iteration and continues with the next one.
2fill in blank
mediumComplete the code to stop the loop when x equals 4.
R Programming
for (x in 1:5) { if (x == 4) { [1] } print(x) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'next' will skip the iteration but not stop the loop.
✗ Incorrect
The break statement stops the entire loop immediately.
3fill in blank
hardFix the error in the code to skip printing number 2.
R Programming
for (i in 1:3) { if (i == 2) { [1] } print(i) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'break' stops the loop entirely.
✗ Incorrect
Use next to skip printing when i is 2.
4fill in blank
hardFill both blanks to skip printing odd numbers and stop the loop at 8.
R Programming
for (num in 1:10) { if (num [1] 2 != 0) { [2] } if (num == 8) { break } print(num) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '%%' for modulo.
Using 'break' instead of 'next' to skip.
✗ Incorrect
Use %% to check remainder and next to skip odd numbers.
5fill in blank
hardFill all three blanks to skip numbers divisible by 3, stop at 7, and print the rest.
R Programming
for (val in 1:10) { if (val [1] 3 == 0) { [2] } if (val [3] 7) { break } print(val) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' to check for 7.
Using 'break' instead of 'next' to skip.
✗ Incorrect
Use %% for modulo, next to skip divisible by 3, and == to stop at 7.