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

Циклы

В Rust есть три ключевых слова для циклов: while, loop и for:

Выражение while

Ключевое слово while работает примерно так же, как и в других языках: выполняет тело цикла, пока условие истинно.

// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0

fn main() {
    let mut x = 200;
    while x >= 10 {
        x = x / 2;
    }
    dbg!(x);
}