100-exercises-to-learn-rust icon indicating copy to clipboard operation
100-exercises-to-learn-rust copied to clipboard

02 - Basic Calculator - If/Else nonsensical example

Open TellyO3 opened this issue 4 months ago • 2 comments

The code below will never print 3, and should not be an if/else. I think it's confusing to new learners to include code that does not do what it suggests. This code prints "number is smaller than 5" for everything < 5 and for anything >=5 it prints "number greater than or equal to 3, but smaller than 5" for any other value.

let number = 3;

if number < 5 {
    println!("`number` is smaller than 5");
} else if number >= 3 {
    println!("`number` is greater than or equal to 3, but smaller than 5");
} else {
    println!("`number` is smaller than 3");
}

This should be changed to an example that actually requires the use of if else and does what it is supposed to do.

TellyO3 avatar Jul 14 '25 11:07 TellyO3