From the course: Rust Programming: From Fundamentals to Advanced Concepts with AI-Assisted Development
Unlock this course with a free trial
Join today to access over 25,600 courses taught by industry experts.
Demo: The match control flow in Rust - Rust Tutorial
From the course: Rust Programming: From Fundamentals to Advanced Concepts with AI-Assisted Development
Demo: The match control flow in Rust
- [Instructor] Match control flow is an interesting way of dealing with different scenarios that you want to handle. In other programming languages, you might see this keyword as a Case. And in Rust it's actually called Match. They don't use Case. The programming language doesn't use Case. So what it is, is that it's trying to match, in this case the name variable to certain possibilities. Each line here represents a distinct possibility. And those possibilities are defined by this thing here on the left. So the way it will work is by having the actual value that it's trying to batch on the left, followed by these two characters, the equal and the greater than character. And then like a given action. Now this could be an expression as well, but in this case it will just be printing. So what will happen here is that the hello variable assigned to name, will go through this Match block here. So name will be hello. And in this case on line number nine, it's not going to match goodbye of…
Contents
-
-
-
-
-
-
-
(Locked)
Introduction to loops and control flow59s
-
(Locked)
Demo: Introduction to loops in Rust3m 28s
-
(Locked)
Demo: Conditional statements in Rust7m 16s
-
(Locked)
Demo: The while loop in Rust3m 14s
-
(Locked)
Demo: The for loop in Rust4m 34s
-
(Locked)
Demo: The break and continue statements3m 29s
-
(Locked)
Demo: The match control flow in Rust5m 14s
-
(Locked)
Summary of loops and control flow41s
-
(Locked)
-
-
-
-
-
-
-
-