Exploring intermediate Rust concepts
In the previous section, we understood a lot of the foundational concepts of Rust. This will help us in reading and deciphering larger programs that we shall encounter in the later chapters of this book. Now, it’s time to build upon the knowledge that we’ve acquired to start understanding slightly more advanced Rust concepts so that we gain a stronger grip on the concepts and deploy them in real-world scenarios.
Control flow
All programming languages have a way to execute different pieces of code that are dependent on meeting a condition. This execution happens with the help of branches, which are usually defined with the help of if
, else
, and else if
. In Rust, we have similar concepts. So, let’s learn about these with the help of some examples:
fn main() { let i = 5; if i > 3 { println!("condition met, i is greater than 3"); ...