keyword

Rust continue: skip to the next iteration

Use `continue` to skip the remaining code in the current loop iteration and move to the next iteration. The loop itself does not end. Expected output: 1 3 5 Why: Even values skip the print statement. Common mistake: Unlike break, continue does not exit the loop.

Formal Syntax & Structure

rust syntaxrust
continue;

Working Example

Example Snippetrust
fn main() {    for n in 1..=5 {        if n % 2 == 0 {            continue;        }        println!("{n}");    }}
Rust Reference