PR3-Rust-SS26/E-enums/04_match_guards.rs

17 lines
455 B
Rust

// Match Guards: ein `if` nach dem Pattern fügt eine zusätzliche Bedingung hinzu.
fn bewerte_note(punkte: u32) {
match punkte {
p if p >= 90 => println!("{p} Punkte → Sehr gut"),
p if p >= 75 => println!("{p} Punkte → Gut"),
p if p >= 50 => println!("{p} Punkte → Bestanden"),
p => println!("{p} Punkte → Durchgefallen"),
}
}
fn main() {
for p in [95, 80, 55, 30] {
bewerte_note(p);
}
}