Rust provides three loop constructs:
loop— Infinite loop until youbreak(can even return a value!).while— Repeats while a condition is true.for— The safest, most common loop for iterating over ranges (1..=5) or collections without index-out-of-bounds bugs.
ADVERTISEMENT