Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

harshil bhatt
PLUS
harshil bhatt
Courses Plus Student 2,722 Points

Inside the body of the loop, we're going to use the multiplier to get the multiple of 6. For example, if the multiplier

please help me out .. the int type in results does not allow me to add string at all , then how do we add

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

for multiplier  in 1...10 {
        var multiplier = (\(multiplier)   \(multiplier * 6))    

}


results +=  multiplier 

2 Answers

Magnus Hållberg
Magnus Hållberg
17,232 Points

If you have a space before the operator you need one after it aswell. Either no spaces or spaces on both sides, else you will get an error.

Magnus Hållberg
Magnus Hållberg
17,232 Points

First of all, the temporary constant is created when you write "multiplier" in the header of the for loop. That becomes the constant. You cant declare it again inside the body of the loop. Second, you are trying some sort of string interpolation for the calculation, delete the hole line inside the body of the loop. Move the "results" line inside the body so that the calculations are iterated through. The calculation is as simple as the multiplier times 6, so you can do results.append(multiplier * 6) or results += [multiplier *6].

harshil bhatt
harshil bhatt
Courses Plus Student 2,722 Points

you can not do multiplier *6 , I have tried all the ways ill show you by giving the code again

var results : [Int] = []

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

}

it shows an error with '' * "