You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-12-22 06:47:49 +02:00
Publish Comprehensive Rust 🦀
This commit is contained in:
20
src/hello-world/small-example.md
Normal file
20
src/hello-world/small-example.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# Small Example
|
||||
|
||||
Here is a small example program in Rust:
|
||||
|
||||
```rust,editable
|
||||
fn main() { // Program entry point
|
||||
let mut x: i32 = 6; // Mutable variable binding
|
||||
print!("{x}"); // Macro for printing, like printf
|
||||
while x != 1 { // No parenthesis around expression
|
||||
if x % 2 == 0 { // Math like in other languages
|
||||
x = x / 2;
|
||||
} else {
|
||||
x = 3 * x + 1;
|
||||
}
|
||||
print!(" -> {x}");
|
||||
}
|
||||
println!();
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user