Fizzbuzz Cheat Sheet
This is a syntax cheat sheet to be used with the Fizzbuzz exercise.
Variables
Functions
// a function with one argument, no return.
fn number_crunch(input: u32) {
// function body
}
// a function with two arguments and a return type.
fn division_machine(dividend: f32, divisor: f32) -> f32 {
// function body
let quotient = dividend / divisor;
// return line does not have a semi-colon!
quotient
}
fn main() {
let cookies = 1000.0_f32;
let cookie_monsters = 1.0_f32;
// calling a function
let number = division_machine(cookies, cookie_monsters);
}
for
loops and ranges
if - statements
Operators (Selection)
Operator | Example | Explanation |
---|---|---|
!= | expr != expr | Nonequality comparison |
== | expr == expr | Equality comparison |
&& | expr && expr | Short-circuiting logical AND |
|| | expr || expr | Short-circuiting logical OR |
% | expr % expr | Arithmetic remainder |
/ | expr / expr | Arithmetic division |