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

Kanishka Bamian
Kanishka Bamian
1,138 Points

Is there someone who explain a bit better that for me?

Inside the body of the loop, we're going to use the multiplier to get the multiple of 6. For example, if the multiplier is 1, then the multiple is 1 times 6, which is equal to 6.

Once you have a value, append it to the results array. This way once the for loop has iterated over the entire range, the array will contain the first 10 multiples of 6.

loops.swift
// Enter your code below
var results: [Int] = []
for number in 1...10 {
    print("\(number) times 6 is equal to \(number * 6)")
}

let multiplier = 6

1 Answer

Magnus Hållberg
Magnus Hållberg
16,953 Points

In a for in loop the word after “for” will be your temporary constant. So when you write your loop like this “for multiplier in 1...10{}” multiplier will be your temporary constant. Also, the challenge tells you to append the value, not to print it to the console. Hope this helps.