Can I use instructions in pattern matching branches?

Is it possible to have instructions in the pattern matching branches?

I tried this, but it does not work. Maybe there is some special syntax to achieve this?

fn main() {
    let x = 5i;

    match x {
        1 => println!("one"),
        _ => println!("something"); // error: expected one of `,`, `}`, found `;`
             println!("else"),
    }
}
+4
source share
1 answer

If you need multiple statements, you should use {}:

fn main() {
    let x = 5i;

    match x {
        1 => println!("one"),
        _ => {
            println!("something");
            println!("else")
        }
    }
}
+12
source

All Articles