ADVERTISEMENT
ADVERTISEMENT

Rust program to demonstrate the if let with else if statement

Rust | if let with else if statement example: Write an example to compare STD codes and print the corresponding city names using if let with else if statement.
Submitted by Nidhi, on October 07, 2021

Problem Solution:

In this program, we will use the else if statement with if let to compare std codes and print the corresponding name of the city.

Program/Source Code:

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

// Rust program to demonstrate the 
// example of if let with else if statements

fn main() 
{
    let stdCode: i32 = 121;
    
    let result = if let 011 = stdCode{
        "Delhi"
    }
    else if 120==stdCode{
        "GHAZIABAD"
    }
    else if 121==stdCode{
        "Meerut"
    }
    else{
        "Unknown"
    };
    
    println!("{}",result);
}

Output:

Meerut

Explanation:

Here, we created a variable stdCode of i32 type with the initial value of 121. Then we compared the value of stdCode using the if let statement with else if statement and return the name of the corresponding city and printed the result.

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.