From 193dd6da8b9c74c0788517db93e91deb85fea314 Mon Sep 17 00:00:00 2001 From: Itshardtogiveyourselfaname <122693427+Itshardtogiveyourselfaname@users.noreply.github.com> Date: Sun, 5 Apr 2026 21:09:59 +0200 Subject: [PATCH] Update for.md I recently discovered the issue for myself, that you can write the following code: for i in 10..1{ println!("Hello World"); } This code does nothing, but you dont get a compiler warning and nothing and this isnt described in the rust handbook either. I dont think I can be the only beginner stumbling over this, so theres a possible solution. I dont know if the way I wrote it fits in with the writing style of the book, but just adjust it as needed :) --- src/flow_control/for.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/flow_control/for.md b/src/flow_control/for.md index 1beab9261c..e9fc3cf62b 100644 --- a/src/flow_control/for.md +++ b/src/flow_control/for.md @@ -46,6 +46,19 @@ fn main() { } ``` +Just remember that even though you can compile the code when a>b, the loop gets +never executed. +```rust,editable +for i in 10..1{ +println!("fizzbuzz"); +} +``` +If you want to count down, you need to use .rev() instead +```rust,editable +for i in (1..10).rev(){ +println!("fizzbuzz"); +} +``` ## for and iterators The `for in` construct is able to interact with an `Iterator` in several ways.