30 lines
1.0 KiB
Rust

fn main() {
// comments go above line attempting to comment
println!("Hello, world!");
example_funct();
}
// implicitly implied that a unit type is returned but neat to know it is allowed
fn example_funct () -> () {
let number = 1;
// allowed bool statement
let run_if = number == 0;
// each if is a different arm or branch of the code path, will not check any other files once the first one is true
// must be a bool, rust will not accept if number or etc, must be converted into bool
if number != 0 {
println!("Number is non-zero")
// multiple ifs in a row
} else if run_if {
println!("Number is zero")
// in the ase that all are flase
} else {
println!("Number is not real")
}
let condition = true;
// ifs can also be part of a statement to set a value depending on another value
let another_number = if condition { 7 } else { 0 };
}
// too many ifs or if elses can clutter code, use the match case instead
// 5 ifs should mean the code needs to be refactored