Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to stop the loop when i equals 3.
Swift
for i in 1...5 { if i == 3 { [1] } print(i) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using continue instead of break, which skips only the current iteration.
✗ 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.
Swift
for i in 1...5 { if i == 3 { [1] } print(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 loop to correctly skip the number 2 and stop at 4.
Swift
for i in 1...5 { if i == 2 { [1] } if i == 4 { break } print(i) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using break to skip 2, which stops the loop too early.
✗ Incorrect
Use continue to skip printing 2, and break to stop at 4.
4fill in blank
hardFill both blanks to skip odd numbers and stop the loop when i is 8.
Swift
for i in 1...10 { if i [1] 2 != 0 { [2] } if i == 8 { break } print(i) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of % to check odd numbers.
Using break instead of continue to skip odd numbers.
✗ Incorrect
Use % to check if a number is odd and continue to skip it.
5fill in blank
hardFill all three blanks to print only even numbers less than 7.
Swift
for i in 1...10 { if i [1] 2 != 0 { [2] } if i [3] 7 { break } print(i) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of >= to stop loop.
Using break instead of continue to skip odd numbers.
✗ Incorrect
Check if number is odd with %, skip with continue, and stop loop when i ≥ 7 using >=.