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.
Multiple conditions - Rust Tutorial
From the course: Rust Essential Training
Multiple conditions
- [Instructor] If expressions can be used for more than just deciding whether or not to execute a single block of code. We can also use them to evaluate multiple conditions to decide which code gets executed among several possible options. For example, let's build an if expression based on these two variables, X and Y. If X is greater than Y, let's print a message saying that. This print statement will get executed if X greater than Y evaluates to true. But if the condition turns out to be false and we want to take a different path, we can do that by adding an else block at the end of the if expression. And for here, we'll print a message that X is not greater than Y. When I run this code, the condition X greater than Y evaluates to false, so it executes the else block instead, printing the message X is not greater than Y. Now, if we think about it, if X is not greater than Y, that could mean that X is less than Y…
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)
-
-
-
-
-
-
-
-
-
-
-
-