Perform the following steps:
- 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 );
}
- Create a variable named age and assign it to an integer with the value 10.
- 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: