diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 43adb7b02d8d..a1644cf78031 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -32,6 +32,8 @@ - [Control Flow Basics](control-flow-basics.md) - [Conditionals](control-flow-basics/conditionals.md) - [Loops](control-flow-basics/loops.md) + - [`for`](control-flow-basics/loops/for.md) + - [`loop`](control-flow-basics/loops/loop.md) - [`break` and `continue`](control-flow-basics/break-continue.md) - [Blocks and Scopes](control-flow-basics/blocks-and-scopes.md) - [Functions](control-flow-basics/functions.md) diff --git a/src/control-flow-basics/loops.md b/src/control-flow-basics/loops.md index 352c08af19fd..db4b1e71243a 100644 --- a/src/control-flow-basics/loops.md +++ b/src/control-flow-basics/loops.md @@ -22,42 +22,3 @@ fn main() { println!("Final x: {x}"); } ``` - -## `for` - -The [`for` loop](https://doc.rust-lang.org/std/keyword.for.html) iterates over -ranges of values: - -```rust,editable -fn main() { - for x in 1..5 { - println!("x: {x}"); - } -} -``` - -## `loop` - -The [`loop` statement](https://doc.rust-lang.org/std/keyword.loop.html) just -loops forever, until a `break`. - -```rust,editable -fn main() { - let mut i = 0; - loop { - i += 1; - println!("{i}"); - if i > 100 { - break; - } - } -} -``` - -
- -- We will discuss iteration later; for now, just stick to range expressions. -- Note that the `for` loop only iterates to `4`. Show the `1..=5` syntax for an - inclusive range. - -
diff --git a/src/control-flow-basics/loops/for.md b/src/control-flow-basics/loops/for.md new file mode 100644 index 000000000000..edbfbaa55c8e --- /dev/null +++ b/src/control-flow-basics/loops/for.md @@ -0,0 +1,20 @@ +# `for` + +The [`for` loop](https://doc.rust-lang.org/std/keyword.for.html) iterates over +ranges of values: + +```rust,editable +fn main() { + for x in 1..5 { + println!("x: {x}"); + } +} +``` + +
+ +- We will discuss iteration later; for now, just stick to range expressions. +- Note that the `for` loop only iterates to `4`. Show the `1..=5` syntax for an + inclusive range. + +
diff --git a/src/control-flow-basics/loops/loop.md b/src/control-flow-basics/loops/loop.md new file mode 100644 index 000000000000..544897eac8ff --- /dev/null +++ b/src/control-flow-basics/loops/loop.md @@ -0,0 +1,17 @@ +# `loop` + +The [`loop` statement](https://doc.rust-lang.org/std/keyword.loop.html) just +loops forever, until a `break`. + +```rust,editable +fn main() { + let mut i = 0; + loop { + i += 1; + println!("{i}"); + if i > 100 { + break; + } + } +} +```