Skip to content

Commit

Permalink
Match Feature Example
Browse files Browse the repository at this point in the history
  • Loading branch information
ramagururadhakrishnan committed May 8, 2024
1 parent abb4218 commit 35937bf
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Assets/Lectures/RL5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 20CYS312 - Principles of Programming Languages
![](https://img.shields.io/badge/Batch-21CYS-lightgreen) ![](https://img.shields.io/badge/UG-blue) ![](https://img.shields.io/badge/Subject-PPL-blue) <br/>
![](https://img.shields.io/badge/Lecture-2-orange) ![](https://img.shields.io/badge/Practical-3-orange) ![](https://img.shields.io/badge/Credits-3-orange)

## Lecture 5 - Misc
![](https://img.shields.io/badge/-8th_May-orange)

```
fn main() {
let number = 13;
// TODO ^ Try different values for `number`
match number {
// Match a single value
1 => println!("One!"),
// Match several values
2 | 3 | 5 | 7 | 11 => println!("This is a prime"),
// TODO ^ Try adding 13 to the list of prime values
// Match an inclusive range
13..=19 => println!("A teen"),
// Handle the rest of cases
_ => println!("Ain't special"),
// TODO ^ Try commenting out this catch-all arm
}
let boolean = true;
// Match is an expression too
let binary = match boolean {
// The arms of a match must cover all the possible values
false => 0,
true => 1,
// TODO ^ Try commenting out one of these arms
};
println!("{} -> {}", boolean, binary);
}
```

0 comments on commit 35937bf

Please sign in to comment.