https://github.com/0xsaksham/branches
A curated set of Rust code snippets demonstrating key language features, from basic conditionals to loops. Ideal for quick reference and learning essentials. 🦀
https://github.com/0xsaksham/branches
practice-programming rust rust-lang
Last synced: about 1 month ago
JSON representation
A curated set of Rust code snippets demonstrating key language features, from basic conditionals to loops. Ideal for quick reference and learning essentials. 🦀
- Host: GitHub
- URL: https://github.com/0xsaksham/branches
- Owner: 0xSaksham
- Created: 2023-11-21T11:59:46.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-12-05T11:13:25.000Z (over 2 years ago)
- Last Synced: 2025-03-11T15:57:42.239Z (over 1 year ago)
- Topics: practice-programming, rust, rust-lang
- Language: Rust
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Rust Code Showcase
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:
## 1. Simple Conditional Statement
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.
## 2. Else If Statement
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.
## 3. If in Let Statement
The `if_in_let` function demonstrates the usage of the `if` statement within a `let` statement, showcasing Rust's expressive syntax.
## 4. Infinite Loop
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.
## 5. Using Continue in a Loop
The `use_continue` function exhibits the `continue` keyword in a `for` loop, skipping even numbers and printing only the odd ones.
## 6. Value from Loop
In the `value_from_loop` function, a loop accumulates a counter until it reaches 10, then breaks, returning the counter multiplied by 2.
## 7. Named Loops
The `named_loops` function showcases nested loops, including a named loop (`'counting_up`), breaking out of the outer loop based on specific conditions.
## 8. While Loop
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! 🦀