Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Increment integers - augmented assignment

#[allow(clippy::assign_op_pattern)]
fn main() {
    let mut x = 1;
    println!("{x}");

    x = x + 1;
    println!("{x}");

    x += 1;
    println!("{x}");

    // Rust has no prefix and postfix increment operator
    // x++;
    // ++x;
}
1
2
3