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
faisalrustom
1,300 Pointsfor in loop error in new xcode
hi, import UIKit
var numbers:[Int] = [1,2,3,4,5,6,7,8,9,10]
for number in numbers { print("(numbers) x 7 = (numbers*7)") }
This is not working the error says "Binary operator '*' cannot be applied to operands of type 'int' and int
please help how do I fix it?
2 Answers
Mark Cranston
1,817 PointsYou are using the variable "numbers" in the print statement instead of the "number" for-in property. So the problem was that you were using an un-initialized variable, so just make sure to use the variable associated with the for-in loop.
import UIKit
var numbers:[Int] = [1,2,3,4,5,6,7,8,9,10]
for number in numbers { print("\(number) x 7 = \(number*7)") }
Mark Cranston
1,817 PointsI think you forgot to add your backslashes... You need them so the program knows that it needs to print the variable, not as an Int but a String.
import UIKit
var numbers:[Int] = [1,2,3,4,5,6,7,8,9,10]
for number in numbers { print("\(numbers) x 7 = \(numbers*7)") }
faisalrustom
1,300 Pointseven with the back slash it's not working.
faisalrustom
1,300 Pointsfaisalrustom
1,300 Pointsthanks alot for the fast response