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

Multiple conditions - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

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…

Contents