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

Loops

Há três palavras-chave de loop em Rust: while, loop e for:

while

A palavra-chave while funciona de maneira muito similar a outras linguagens, executando o corpo do loop enquanto a condição for verdadeira.

fn main() {
    let mut x = 200;
    while x >= 10 {
        x = x / 2;
    }
    println!("X final: {x}");
}