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

loop

Оператор loop повторяется бесконечно, пока не встретится break.

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

fn main() {
    let mut i = 0;
    loop {
        i += 1;
        dbg!(i);
        if i > 100 {
            break;
        }
    }
}
  • Оператор loop работает как цикл while true. Используйте его для таких задач, как серверы, которые обслуживают соединения бесконечно.