How to find all the numbers divisible by another number in fast?

advertisements

How do I find all the numbers divisible by another number in swift that have a remainder of 0? This is a Fizzbuzz related question.

Lets say that...

let number = 150

And I want to do something like...

print("Fizz") // for all the numbers where the remainder of number % 3 == 0.

So if number was 15, it would print "Fizz" 5 times.


This will work

let number = 150

for num in 1...number {
    if num % 3 == 0 {
        print("Fizz :\(num)")
    }
}