r/shittyprogramming • • Oct 06 '21

FizzBuzz compact version

fn main(){for num in 1..101{if num%5==0&&num%3==0{println!("FizzBuzz")}else if num%5==0{println!("Buzz")}else if num%3==0{println!("Fizz")}else{println!("{}",num)}}}
46 Upvotes

11 comments sorted by

View all comments

Show parent comment

14

u/[deleted] Oct 06 '21

I'll update it still learning sorry 🤷‍♂️👍

13

u/BobGeneric Oct 06 '21

Next skip the if's and else's... that's luxury and unnecessary. Real programmers only use ternaries. Better yet if you negate the condition, and avoid the use of parentesis.

4

u/[deleted] Oct 11 '21

I'm not sure if rust has ternaries lol, next I'll try a macro to get it shorter