iOS ● ○ ○ Swift 6

Kodebits Day 75: Range Iteration

Aug 13 2026
Practice ranges with a short swift challenge.

What is the output?

var sum = 0
for i in 1...4 {
  sum += i
}
print(sum)
for i in 2..<5 {
  print(i, terminator: " ")
}


Try it in the online Swift Playground →

[spoiler title="Solution"]

Answer:

10
2 3 4

Explanation:

Closed ranges include endpoints; half-open exclude the upper bound.

[/spoiler]


Further Reading