mirror of
https://github.com/rust-lang/book.git
synced 2026-05-16 23:10:40 -04:00
Per https://github.com/rust-lang/book/issues/3047, use captured identifiers instead of the positional ones for some examples, e.g. ```diff - println!("Worker {} got a job; executing.", id); + println!("Worker {id} got a job; executing."); ```
780 B
780 B
% Loops
There is a new edition of the book and this is an old link.
Rust has three kinds of loops:
loop,while, andfor. Theloopkeyword tells Rust to execute a block of code over and over again forever or until you explicitly tell it to stop.whileloops evaluate a block of code until a condition ceases to be true. Aforloop executes some code for each item in a collection.
loop {
println!("again!");
}
let mut number = 3;
while number != 0 {
println!("{number}!");
number = number - 1;
}
let a = [10, 20, 30, 40, 50];
for element in a.iter() {
println!("the value is: {element}");
}
You can find the latest version of this information here.