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 Basics (retired) Control Flow For-In Loop

Jake N
Jake N
612 Points

in the video your not explaining how {} work...

all of a sudden it skips down lines and print pops up. hows that happen, i type it into the answer on the challenge (replacing the 2s with 7s) and it doesn't work

for_loops.swift
for number in 1...10 {

5 Answers

Stone Preston
Stone Preston
42,016 Points

the task states Use a for-in loop to print out a "7 times table". Your output should look like this:

1 * 7 = 7

2 * 7 = 14

Etc., all the way up to 10. Each line should be on a new line.

we can use a range and a for loop to loop through all the numbers 1 through 10.

we can then use string interpolation to interpolate the number variable, and the number variable * 7 to create the desired output

for number in 1...10 {
println("\(number) * 7 = \(number  * 7)")
}
Stone Preston
Stone Preston
42,016 Points

you use { } to create code blocks, or pieces of code that are grouped together. blocks of code like this are common when using loops, functions, etc

at 4:39 of this video amit opens a new block of code ( {} ) after the for in loop.

he then manually types print and selects println from autocomplete. it does not just pop up. the code challenge engine is not xcode, so it does not support code completion. you will have to type all code out yourself

Jake N
Jake N
612 Points

no, what I'm saying is it randomly goes from this line {

to down here } and he doesn't explain how you do that

Stone Preston
Stone Preston
42,016 Points

oh, you press enter/return.

for number in 1...10 {  //then press return a few times to create new lines

} // then add the brace

is that what you mean?

Jake N
Jake N
612 Points

i still can't figure out what the answer is, i feel like i am typing it in right but its still saying wrong, the error doesn't explain whats wrong about it

Jake N
Jake N
612 Points

ah okay thanks, i think i was leaving out the second \