1 println! & main
Programs start in fn main(). println! is a macro (note the !) with {} placeholders for values.
fn main() {
println!("Hello, Rust!");
let x = 5;
let y = 8;
println!("{} + {} = {}", x, y, x + y);
}
println! macros, let bindings, mutability and loops.
Programs start in fn main(). println! is a macro (note the !) with {} placeholders for values.
fn main() {
println!("Hello, Rust!");
let x = 5;
let y = 8;
println!("{} + {} = {}", x, y, x + y);
}
Bindings are immutable by default — add mut to allow change. This default is central to Rust's safety.
fn main() {
let mut count = 0;
count = count + 10;
let name = "Ferris";
println!("{} counted to {}", name, count);
}
Rust offers for, while and infinite loop. The range 1..=5 is inclusive on both ends.
fn main() {
let mut sum = 0;
for i in 1..=5 {
sum += i;
println!("i = {}", i);
}
println!("sum = {}", sum);
}
Code runs on a learning-oriented simulated runtime that supports common constructs (output, variables, arithmetic, conditionals and loops).
7 tasks across 3 pages — multiple-choice and fill-in (type the answer). Score 70% or higher to earn your certificate.
🔒 Pass the quiz above (70%+) to unlock your downloadable certificate.
Congratulations! Enter your name to generate your certificate.