5 ms·
It's to neatly handle the line break.
by donmcc 12y ago
It's to neatly handle the line break.
- vessenes 12y agoI suppose it's a style issue as to whether an extra mod is better than checking if one of the triggers has passed. I would propose it's more DRY to do it the short way though.
- pcmonk 12y agoIt's not any shorter. The extra check as to whether or not to print the line break cancels out the mod 15 check. In my opinion, it's cleaner to have three conditionals of the same type than two checking mods and a third checking the OR of the first two. Of course, it can be actually shorter with a goto.
- boomlinde 12y agoWhether you print the number, Fizz, Buzz or FizzBuzz you are going output a line break, so I'm not sure what you would be checking for. Output \n unconditionally.
- deleted 12y ago[deleted]
- zem 12y agothen you'd get \n \n fizz\n \n buzz\n rather than fizz\n buzz\n
- blt 12y agoThen you call `printf` twice every loop instead of once. `printf` is buffered so you aren't making two system calls, but you are still making two function calls.
- boomlinde 12y agoMaybe it's a performance/brevity compromise, but the latter is the issue the I addressed. The least-calls solution would probably be to print the whole output as a single string constant.
- stonemetal 12y agostring output = numb.toString(); if(numb % 3 == 0) ouput = "Fizz"; if(numb % 5 == 0) output.Append("Buzz"); write output; It is possible to use two checks to cover all three fizzbuzz components.
- im2w1l 12y ago5Buzz
- mden 12y agoIn some languages you can hide the extra check: for i in range(1,100):print("Fizz"(i%3==0) + "Buzz"(i%5==0) or i)
- thedufer 12y agoFor others who are confused by this syntax, it appears that there are *'s that got eaten and turned into italics.