From b7ebf8608af058e6cc3c0fba3a364fc5a74e3e09 Mon Sep 17 00:00:00 2001 From: lalmendra <109772135+lalmendra@users.noreply.github.com> Date: Fri, 2 Oct 2026 04:02:55 -0300 Subject: [PATCH] Fix infinite loops In the first two examples, decrementing x inside the inner loop causes the loop to run indefinitely. Also fixed the third example to keep the same pattern. --- src/loops/nested_loops.md | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/loops/nested_loops.md b/src/loops/nested_loops.md index 2de9c342..5c98daa4 100644 --- a/src/loops/nested_loops.md +++ b/src/loops/nested_loops.md @@ -9,16 +9,17 @@ int y = 3; while (x != 0) { while (y != 0) { - IO.println( - "x is " + x - ); IO.println( "y is " + y ); - x--; y--; } + + IO.println( + "x is " + x + ); + x--; } ~} ``` @@ -36,16 +37,16 @@ while (x != 0) { break; } - IO.println( - "x is " + x - ); IO.println( "y is " + y ); - - x--; y--; } + + IO.println( + "x is " + x + ); + x--; } ~} ``` @@ -60,18 +61,16 @@ while (x != 0) { break; } while (y != 0) { - - - IO.println( - "x is " + x - ); IO.println( "y is " + y ); - - x--; y--; } + + IO.println( + "x is " + x + ); + x--; } ~} ```