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

Having trouble appending to array

I'm still not sure how to append to the array. Any ideas?

loops.swift
// Enter your code below
var results: [Int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for multiplier in 1...10 {

}

3 Answers

Steven Parker
Steven Parker
174,115 Points

First, you don't want to place any values into the array before the loop starts. The code in the loop will fill the array in.

Your loop looks good, so now you could use the "append" method on the array to add a new element, giving it a value six times larger than the "multiplier".

So that would look like this:

var results: [Int] = []
for multiplier in 1...10 { 
  results.append(multiplier * 6)
}

Can you show me what that looks like?

Steven Parker
Steven Parker
174,115 Points

OK, I expanded my answer.

Thanks! I was so close!

Steven Parker
Steven Parker
174,115 Points

Glad to help, "cousin". :wink: And happy coding!