This repository contains a collection of Rust code snippets that demonstrate various concepts in the Rust programming language. The code covers topics such as conditional statements, loops, and control flow. Let's explore what each section entails:
The main
function begins with a basic conditional statement that checks if a number is less than 5 and prints either "True" or "False" accordingly.
The else_if
function showcases an example of an "else if" statement. It determines whether a number is even or odd and prints the result.
The if_in_let
function demonstrates the usage of the if
statement within a let
statement, showcasing Rust's expressive syntax.
The infinite_loop
function contains a loop that runs indefinitely, demonstrating how to create an infinite loop and stop it using CTRL+C in the terminal.
The use_continue
function exhibits the continue
keyword in a for
loop, skipping even numbers and printing only the odd ones.
In the value_from_loop
function, a loop accumulates a counter until it reaches 10, then breaks, returning the counter multiplied by 2.
The named_loops
function showcases nested loops, including a named loop ('counting_up
), breaking out of the outer loop based on specific conditions.
The while_loop
function illustrates a simple while
loop that counts down from 3 to 0, printing the current number in each iteration.
Feel free to explore, modify, and use these code snippets as a reference for learning Rust programming concepts. If you have any questions or improvements, please don't hesitate to contribute or open an issue.
Happy coding in Rust! 🦀