Skip to content

Commit

Permalink
Add more examples in main file
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-saad-la committed Jul 2, 2024
1 parent 0d1d0e9 commit 335cb3f
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion code/03_control_flow/if_statement/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,38 @@ fn simple_if_statement() {
// }

// Warning code

fn if_with_parentheses() {
let num = 7;
#[allow(unused_parens)]
if (num > 0) {
println!("{} is positive number", num);
}
}

// another example

fn with_without_parens() {
let number = 5;

// Both styles are valid
if number > 0 {
println!("No parentheses needed.");
}

// You will get warning here
// you can suppress the warning though
#[allow(unused_parens)]
if (number > 0) {
println!("Parentheses are optional.");
}
}

// Erroneous code, non-boolean-evaluation

fn non_bool_eval() {
let num = 7;

if num {
println!("{} is positive.", num);
}
}

0 comments on commit 335cb3f

Please sign in to comment.