From the course: Rust Essential Training

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Statements vs. expressions

Statements vs. expressions - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Statements vs. expressions

- [Instructor] I want to take a moment to talk about two terms you've heard me use throughout this course, statements and expressions, to explain what they are and how they're different from each other. A statement is an instruction that performs an action, but in the end it doesn't have an output. It doesn't return a value that can be used elsewhere. We write statements in Rust as instructions that end with a semicolon. For example, x = 1 is a statement because it performs its action, assigning the value 1 to x, but we don't get anything back as output after it. Rust will not allow us to use that statement as the value to assign to another variable because that statement doesn't represent a value, it's just an action. An expression, on the other hand, does evaluate to produce a resulting value that can be used elsewhere. Expressions in Rust do not have a semicolon. In fact, if you add a semicolon to the end of an…

Contents