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
Mohammed Hossain
555 PointsTrying to make a program to show me prime numbers (Swift)
let numbers = 1...10
for number in numbers {
if (number * 1 == number) {
println("\(number) is prime")
} else if (number * 2 == number) {
println("\(number) is odd")
}
}
Okay so this is what i typed out. I am trying to show all the prime numbers just from 1-10. can anyone help me out? Thanks in advance!
1 Answer
William Li
Courses Plus Student 26,868 PointsHi, Mohammed Hossain , there's a fault in the conditional logic here.
if (number * 1 == number)
For any number, number * 1 == number will always return true.
Mohammed Hossain
555 PointsMohammed Hossain
555 PointsSo how do i program it to show me prime numbers? i understand how that will always be true.