Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to stop the loop when i equals 3.
Kotlin
for (i in 1..5) { if (i == 3) { [1] } println(i) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using continue instead of break, which skips the current iteration but does not stop the loop.
✗ Incorrect
The break statement stops the loop immediately when the condition is met.
2fill in blank
mediumComplete the code to skip printing the number 3 but continue the loop.
Kotlin
for (i in 1..5) { if (i == 3) { [1] } println(i) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using break instead of continue, which stops the loop entirely.
✗ Incorrect
The continue statement skips the current iteration and continues with the next one.
3fill in blank
hardFix the error in the code to correctly skip printing even numbers.
Kotlin
for (num in 1..6) { if (num % 2 == 0) [1] println(num) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using break causes the loop to stop early, not skip iterations.
✗ Incorrect
Using continue skips printing even numbers but continues the loop.
4fill in blank
hardFill both blanks to create a loop that prints numbers 1 to 5 but stops before 4.
Kotlin
for (i in 1..5) { if (i [1] 4) { [2] } println(i) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using continue instead of break, which skips but does not stop the loop.
✗ Incorrect
The condition i >= 4 checks if i is 4 or more, and break stops the loop when i is 4 or more.
5fill in blank
hardFill all three blanks to print only odd numbers from 1 to 7.
Kotlin
for (n in 1..7) { if (n [1] 2 == 0) { [2] } println([3]) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using break instead of continue, which stops the loop early.
✗ Incorrect
The modulo operator % checks for even numbers, continue skips them, and n prints the current number.