How to do it...

Perform the following steps:

  1. Create a file named condition.rs and enter the following code to the script:
        use std::{i32};
fn main() {
let age : i32= 10;
// If else statements
if age <= 18{
println!("Go to School");
} else if (age >18) && (age <= 28){
println!("Go to college");
} else {
println!("Do something with your life");
}

// if/ else statement in one line
let can_vote = if (age >= 18) {true} else
{false};
println!("Can vote {}",can_vote );
}
  1. Create a variable named age and assign it to an integer with the value 10.
  2. The preceding code has an if...else statement to make a decision about the age value. It performs print operations based on the conditions.

You should get the following screenshot as output upon running the preceding code:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.117.214