Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Swift track - FizzBuzz Generator

I just finished doing the FizzBuzz Generator, why do we add the 0 as described on the video solution ?

Meaning I was able to visualize setting the numbers 1...20, but why do we need to put the 0 for example: if i % 3 == 0 or if i %5 == 0 ?

1 Answer

Chris Shaw
Chris Shaw
26,650 Points


The zero is required as without it the statement can result in something other than true which is not what we're looking, for instance.

if 3 % 3 {
  println("This should never execute!")
} else {
  println("This should execute!")

So in the above example we're expecting a truthy value but instead because 3 % 3 equals 0 it's implied as false because 0 and false are the same thing when compared to each other.