Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start an infinite repeat loop.
R Programming
repeat [1] { print("Hello") break }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or square brackets instead of curly braces.
Forgetting to open the block with {.
✗ Incorrect
In R, a repeat loop starts with the keyword 'repeat' followed by a block enclosed in curly braces { }.
2fill in blank
mediumComplete the code to break out of the repeat loop when x is greater than 5.
R Programming
x <- 1 repeat { if (x [1] 5) break print(x) x <- x + 1 }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= or < which break too early.
Using == which breaks only when x equals 5.
✗ Incorrect
The break should happen when x is greater than 5, so the condition is x > 5.
3fill in blank
hardFix the error in the repeat loop to correctly increment x and break when x equals 3.
R Programming
x <- 0 repeat { x <- x [1] 1 if (x == 3) break print(x) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting to increment x causing an infinite loop.
✗ Incorrect
To increase x by 1 each time, use the + operator.
4fill in blank
hardFill both blanks to create a repeat loop that prints numbers 1 to 4 and breaks after.
R Programming
x <- 1 repeat { print(x) x <- x [1] 1 if (x [2] 5) break }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong operators for increment or condition.
Breaking too early or too late.
✗ Incorrect
Increment x by 1 each time and break when x is greater or equal to 5.
5fill in blank
hardFill all three blanks to create a repeat loop that sums numbers from 1 to 5 and breaks after.
R Programming
sum <- 0 x <- 1 repeat { sum <- sum [1] x x <- x [2] 1 if (x [3] 6) break } print(sum)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong operators for addition or comparison.
Breaking too early or forgetting to increment.
✗ Incorrect
Add x to sum, increment x by 1, and break when x is 6 or more.