Functions
Last updated
Last updated
We've already discussed functions a bit, but let's do a bit more digging. As of right now, we've only seen the main
function. But let's create another function:
This will print out:
As alluded to the section , Rust functions can have parameters but the parameters must have a type.
If a function has a return value, then it's type also must be declared.
Statements are instructions that perform some action and do not return a value. Expressions evaluate to a resulting value. Let’s look at some examples.
Let's clarify that with some sample code:
You might have noticed that x + 1
didn't have a semicolon after it. That is because it is an expression and not a statement. Per the :