It is common in computing, to come across a conditional statement that contains a lot of ANDs, ORs and more. With rust-lang's powerful match
statement, a programmer can easily convey the message, let's see how.
match
statements takes pattern matching to another level. Using the simple syntax, one can also achieve what nested/ladder if
-else
blocks could. Here is a sample if
-else
code block.
if year%4 == 0 {
if year%100 != 0 || year%400 == 0 {
println!("Leap Year");
} else {
println!("Not a Leap Year");
}