What is the convention for naming functions?
Rust convetion is to use snake case for function and variable names meaning all the letters are lowercase and underscores separate words.
Does Rust care where you define a function?
No, Rust doesn’t care where you defined a function only that they’re defined somewhere in a scope that can be seen by the caller.
Do you need to declare the type in function signatures?
Yes, in Rust you must declare the tyupe of each parameter. Each parameter declaration is seperated with commas.
fn test_function(x_coord:i32, y_coord:i32, z_coord:i32){
}What are statements?
Statements are instructions that perform some action and do not return a value
What are expressions?
Expressions evaluate to a resultant value
Does Rust automatically try to convert non-Boolean types to a Boolean in an if expression?
No, unlike Ruby and Javascript Rust will not automatically try to convert non-Boolean types to a Boolean
Why can’t you have different types when using an if block in variable assignment?
Variables must have a single type, and Rust needs to know at compile time what type the variable is.
let condition = true;
let number = if condition {5} else {"six"}; // returns an errorWhat are the three kinds of loops that rust has?
loop, while, and for
What is the loop keyword in Rust?
The loop keyword tells Rust to execute a block of code over and over again forever until it’s explicitly told to stop. One of the uses of a loop is to try an operation that is known to probably fail such as checking whether a thread has completed its job.
How might you provide the value you got out of the loop to a variable?
let mut counter = 0;
let result = loop {
counter += 1;
if counter == 10 {
break counter * 2;
}
};Difference between break and return?
break only exists the current loop, return always exits the current function