Hacker symbol

November 13, 2019 ~ 1 min read

Expressions VS Statements


Statements are instructions that perform some action and do not return a value.

Expressions evaluate to a resulting value.

// Expression
fn main() {
    let condition = true;
    // this is if is an expression
    let number = if condition {
        5
    } else {
        6
    };

    // this is a stament
    println!("The value of number is: {}", number);
}

Remember that blocks of code evaluate to the last expression in them, and numbers by themselves are also expressions. In this case, the value of the whole if expression depends on which block of code executes


Sebastian BolaƱos

Hi, I'm Sebastian. I'm a software developer from Costa Rica. You can follow me on Twitter. I enjoy working on trustless systems.