Functions
- Statement - instructions that perform some action and do not return a value.
- Expression - evaluate to a resulting value.
This is a statement:
let x = 5;
This is an expression:
5
Statements do not return values. Therefore, you can’t assign a let statement to another variable.
let x = (let y = 6); //Error
Calling a function is an expression (hello()
), calling a macro is an expression (println!("Guess the number!")
), and the block used to create new scopes {}
is an expression:
{
let x = 5;
x - 2
}
The above expression evaluates to 3
.
Expressions do not include semi-colons. If you add a semi-colon, it becomes a statement and will not return a value.