Q:

Rust program to demonstrate the else if let statements

belongs to collection: Rust if/else Programs

0

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

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 else if let statement is given below. The given program is compiled and executed successfully.

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

fn main() 
{
    let stdCode: i32 = 121;
    
    let result = if let 011 = stdCode{
        "Delhi"
    }
    else if let 120=stdCode{
        "GHAZIABAD"
    }
    else if let 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 else if let statement and return the name of the corresponding city and printed the result.

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

total answers (1)

Rust program to demonstrate the if let with else i... >>
<< Rust program to demonstrate the if let statement...