ADVERTISEMENT
ADVERTISEMENT

Rust program to demonstrate the match statement with multiple values

Rust | match statement with multiple values example: Given a number (week number), we have to find the weekday.
Submitted by Nidhi, on October 04, 2021

Problem Solution:

Here, we will demonstrate the match statement with multiple values and print the appropriate message.

Program/Source Code:

The source code to demonstrate the match statement with multiple values is given below. The given program is compiled and executed successfully.

// Rust program to demonstrate the 
// match statement with multiple values

fn main() {
    let mut num:i32 = 5;
    
    match num {
    1=> println!("One"),
    2|3=> println!("Two or Three"),
    4|5|6=> println!("Four or Five or Six"),
    7=> println!("Seven"),
    _=> println!("Invalid number")
    };
}

Output:

Monday

Explanation:

Here, we created an integer variable num with an initial value of 5. Then we created a match block with multiple values and printed the appropriate message.

Rust match 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.