From the course: Rust Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Conditional execution - Rust Tutorial
From the course: Rust Essential Training
Conditional execution
- [Instructor] The simple programs we've written thus far have all executed their instructions sequentially in order from start to finish, but there may be times when we want to change the order in which those instructions get executed based on something that happens when the program runs. Perhaps we don't want to execute certain parts of the code, or maybe we want to repeat a set of instructions multiple times. Rust has several mechanisms we can use to control the flow of a program's execution in those ways. If expressions let us control which code gets executed depending on conditions the program can evaluate at runtime. It's like choosing which path to take when you reach a fork in the road. To demonstrate that, let's write an if expression to conditionally execute some code based on the value of x, which is declared here on line two. We start a new if expression with the keyword if followed by the condition, which is an…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Conditional execution3m 38s
-
(Locked)
Multiple conditions3m 45s
-
(Locked)
Conditional assignment3m 41s
-
(Locked)
Loops3m 45s
-
(Locked)
While loops4m 55s
-
(Locked)
For loops6m 35s
-
(Locked)
Nested loops2m 51s
-
(Locked)
Challenge: Max, min, mean1m 13s
-
(Locked)
Solution: Max, min, mean2m 25s
-
(Locked)
-
-
-
-
-
-
-
-
-
-
-
-