For Loop in Swift

Level 240 keystrokes

Loops over the closed range 1...5 with for-in and prints "Number: 1" to "Number: 5".

Swift code

// 1...5 is a closed range that includes 5 (1..<5 would stop at 4)
1for i in 1...5 {
// Prints Number: 1 to Number: 5, one per line
2 print("Number: \(i)")
3}

Output

Number: 1
Number: 2
Number: 3
Number: 4
Number: 5
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Swift code and how often they appear.

  • .× 3
  • "× 2
  • (× 2
  • )× 2
  • :× 1
  • {× 1
  • }× 1
  • \× 1

More Swift examples at level 2

← Swift typing practice