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

Jihong Min
Jihong Min
2,156 Points

Almost done but stuck... please help!

The complier keeps giving me this msg and I don't know what to do from here. " Make sure the results array contains the first 10 multiples of 6"

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

for multiplier in 1...10 { 
   results = [multiplier * 6]
} 

1 Answer

Rogier Nitschelm
Rogier Nitschelm
iOS Development Techdegree Student 5,460 Points

You are currently reassigning the results variable in every iteration. This means that the result will be:

[6] // first iteration
[12] // second iteration
[18] // third iteration
# ...
[60] // and eventually

This means the result will be [60] (the last assignment inside the loop).

Instead of trying to reassign the results-variable in every iteration, you want to add an element to it in every iteration. See if you can use the .append method to do this. Instead of results = [...]