From d9dc4e99d4d598d8edb8e34ac8961110a2883b03 Mon Sep 17 00:00:00 2001 From: "Dr. Martin Goik" <goik@hdm-stuttgart.de> Date: Mon, 7 Dec 2020 15:23:02 +0100 Subject: [PATCH] Numberguess no break solution --- Doc/Sd1/statements.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Doc/Sd1/statements.xml b/Doc/Sd1/statements.xml index ac29cdec0..584613774 100644 --- a/Doc/Sd1/statements.xml +++ b/Doc/Sd1/statements.xml @@ -5555,6 +5555,21 @@ try (final Scanner scan = new Scanner(System.in)) { System.out.println("Game over, try another run?"); } }</programlisting> + + <para>In case you don't like <code>break</code> statements the + following variant also solves the problem:</para> + + <programlisting language="none">... +boolean numberWasFound = false; + +for (int i = 0; <emphasis role="red">!numberWasFound &&</emphasis> i < numOfUserAttempts; i++) { + ... + } else { + numberWasFound = true; + <emphasis role="red">// No »break« statement required anymore</emphasis> + } +} +...</programlisting> </answer> </qandaentry> </qandadiv> -- GitLab