1分钟内可阅读完
译文 · 基于 Comprehensive Rust
原文链接: https://google.github.io/comprehensive-rust/control-flow-basics/loops.html
Rust 中有三个循环关键字:while、loop 和 for:
while
loop
for
while 关键字 的用法与其他语言非常相似:只要条件为真,就执行循环体。
1 2 3 4 5 6 7 8 9
// Copyright 2023 Google LLC // SPDX-License-Identifier: Apache-2.0 fn main() { let mut x = 200; while x >= 10 { x = x / 2; } dbg!(x); }
01-for 循环 — Comprehensive Rust
02-loop 循环 — Comprehensive Rust