Q:

Rust program to demonstrate the if let statement

0

In this program, we will demonstrate the if let statement by comparing a floating-point value and print the result.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to demonstrate the if let statement is given below. The given program is compiled and executed successfully.

// Rust program to demonstrate the 
// example of if let statement

fn main() 
{
    let num: f32 = 16.0;
    
    let result = if let 16.0=num{
        "Hello"
    }
    else{
        "Hiii"
    };
    
    println!("{}",result);
}

Output:

Hello

Explanation:

Here, we created a variable num of f32 type with an initial value of 16.0. Then we compared the value of num using the if let statement and return the string value. After that, we printed the returned value.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now