ADVERTISEMENT
ADVERTISEMENT

Rust program to demonstrate the if let statement

Rust | if let statement example: Write an example to compare floating-point value using if let statement.
Submitted by Nidhi, on October 07, 2021

Problem Solution:

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

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.

Rust if/else Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.