Array Creation in Swift
Level 287 keystrokes
Creates an array with a literal, prints each element with a for-in loop and then prints the count, 5.
Swift code
// Array literal; the type [Int] is inferred1let nums = [1, 2, 3, 4, 5]// num takes each element in order2for num in nums { // Prints 1 to 5, one per line3 print(num)4}// count is the number of elements: Count: 55print("Count: \(nums.count)")Output
1 2 3 4 5 Count: 5
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.
,× 4(× 3)× 3"× 2:× 1.× 1[× 1]× 1{× 1}× 1