Rust is a systems programming language that focuses on safety, speed, and concurrency. It provides memory safety guarantees and prevents many common programming errors.
Here's a basic "Hello, World!" program in Rust:
fn main() {
println!("Hello, World!");
}
Rust supports variables and operations similarly to other languages:
fn main() {
let a = 10;
let b = 5;
let sum = a + b;
let product = a * b;
println!("Sum: {}", sum);
println!("Product: {}", product);
}
Using conditional statements in Rust:
fn main() {
let number = 10;
if number > 0 {
println!("The number is positive.");
} else {
println!("The number is not positive.");
}
}
Example of a loop in Rust:
fn main() {
for i in 1..=5 {
println!("Number: {}", i);
}
}