iOS Swift Collections and Control Flow Control Flow With Loops For In Loops

Jihong Min
Jihong Min
1,091 Points

I'm stuck on appending the value of the loop to the results array. How do you code the result of the loop?

I know that it should be sth like this but don't know what should be inside those parentheses.

results.append(?)

loops.swift
// Enter your code below
var results: [Int] = []

for multiplier in 1...10 { 
  print("\(multiplier * 6)")
}

1 Answer

Jhoan Arango
MOD
Jhoan Arango
Treehouse Moderator 12,179 Points

Hello,

Array's have a method called "append()". This method will add or "append" values into the array.

// Enter your code below
var results: [Int] = []

for multiplier in 1...10 {
  let result = multiplier * 6

/// using the append method to add a result to the array
  results.append(result)
}

Hope this helps you