<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[while Schleife mit continue und break]]></title><description><![CDATA[<p>Hallo liebe Gemeinde.</p>
<p>Ich wollte ein Programm schreiben, bei dem ich zwei Zahlen kleiner als 100 miteinander Vergleiche. Wenn eine der beiden Zahlen größer als 100 ist, soll abgebrochen werden.</p>
<p>Folgenden Programmcode habe ich aufgesetzt:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

int main()
{
   float x, y;
   cout &lt;&lt; &quot;Geben Sie zwei Zahlen zwischen 0 und 100 ein!&quot; &lt;&lt; endl;
   cout &lt;&lt; &quot;x:&quot;;
   cin  &gt;&gt; x;
   cout &lt;&lt; &quot;y:&quot;;
   cin  &gt;&gt; y;

   while((x&lt;=100)&amp;&amp;(y&lt;=100))
   {
      if(x&lt;y)
      {
         cout &lt;&lt; &quot;x = &quot; &lt;&lt; x &lt;&lt; &quot; ist kleiner als y = &quot; &lt;&lt; y &lt;&lt; endl;
      }
      if(y&lt;x)
      {
         cout &lt;&lt; &quot;y = &quot; &lt;&lt; y &lt;&lt; &quot; ist kleiner als x = &quot; &lt;&lt; x &lt;&lt; endl;
      }
      if(x||y &gt; 100)
      {
         cout &lt;&lt; &quot;Abbruch!&quot; &lt;&lt; endl;
         break;
      }
      continue;
   }

   return 0;
}
</code></pre>
<p>So einfach wie das Programm ist, es ist ein Fehler drinnen, auf den ich einfach nicht komme:</p>
<p>Wenn ich z. Bsp. x = 55 und y = 56 ist, kommt folgende Ausgabe:</p>
<pre><code class="language-cpp">Geben Sie zwei Zahlen zwischen 0 und 100 ein!
x: 55
y: 56
x = 55 ist kleiner als y = 56
Abbruch!
</code></pre>
<p>Wo liegt der Denkfehler? Ich komme nicht drauf!</p>
<p>Vielen Dank für die Antworten im Voraus.</p>
<p>Gruß</p>
<p>Max</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/309234/while-schleife-mit-continue-und-break</link><generator>RSS for Node</generator><lastBuildDate>Wed, 05 Aug 2026 12:09:28 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/309234.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 17 Oct 2012 18:03:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to while Schleife mit continue und break on Wed, 17 Oct 2012 18:03:21 GMT]]></title><description><![CDATA[<p>Hallo liebe Gemeinde.</p>
<p>Ich wollte ein Programm schreiben, bei dem ich zwei Zahlen kleiner als 100 miteinander Vergleiche. Wenn eine der beiden Zahlen größer als 100 ist, soll abgebrochen werden.</p>
<p>Folgenden Programmcode habe ich aufgesetzt:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

int main()
{
   float x, y;
   cout &lt;&lt; &quot;Geben Sie zwei Zahlen zwischen 0 und 100 ein!&quot; &lt;&lt; endl;
   cout &lt;&lt; &quot;x:&quot;;
   cin  &gt;&gt; x;
   cout &lt;&lt; &quot;y:&quot;;
   cin  &gt;&gt; y;

   while((x&lt;=100)&amp;&amp;(y&lt;=100))
   {
      if(x&lt;y)
      {
         cout &lt;&lt; &quot;x = &quot; &lt;&lt; x &lt;&lt; &quot; ist kleiner als y = &quot; &lt;&lt; y &lt;&lt; endl;
      }
      if(y&lt;x)
      {
         cout &lt;&lt; &quot;y = &quot; &lt;&lt; y &lt;&lt; &quot; ist kleiner als x = &quot; &lt;&lt; x &lt;&lt; endl;
      }
      if(x||y &gt; 100)
      {
         cout &lt;&lt; &quot;Abbruch!&quot; &lt;&lt; endl;
         break;
      }
      continue;
   }

   return 0;
}
</code></pre>
<p>So einfach wie das Programm ist, es ist ein Fehler drinnen, auf den ich einfach nicht komme:</p>
<p>Wenn ich z. Bsp. x = 55 und y = 56 ist, kommt folgende Ausgabe:</p>
<pre><code class="language-cpp">Geben Sie zwei Zahlen zwischen 0 und 100 ein!
x: 55
y: 56
x = 55 ist kleiner als y = 56
Abbruch!
</code></pre>
<p>Wo liegt der Denkfehler? Ich komme nicht drauf!</p>
<p>Vielen Dank für die Antworten im Voraus.</p>
<p>Gruß</p>
<p>Max</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2261464</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2261464</guid><dc:creator><![CDATA[silent_max]]></dc:creator><pubDate>Wed, 17 Oct 2012 18:03:21 GMT</pubDate></item><item><title><![CDATA[Reply to while Schleife mit continue und break on Wed, 17 Oct 2012 18:06:20 GMT]]></title><description><![CDATA[<p>silent_max schrieb:</p>
<blockquote>
<pre><code class="language-cpp">if(x||y &gt; 100)
</code></pre>
</blockquote>
<pre><code class="language-cpp">if(x &gt; 100 || y &gt; 100)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2261465</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2261465</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Wed, 17 Oct 2012 18:06:20 GMT</pubDate></item><item><title><![CDATA[Reply to while Schleife mit continue und break on Wed, 17 Oct 2012 18:10:47 GMT]]></title><description><![CDATA[<p>Ersteinmal Danke für Deine schnelle Antwort.</p>
<p>Den Fehler hat es behoben.</p>
<p>Jedoch ist jetzt ein neuer Fehler aufgetreten, den ich nicht sehe.</p>
<p>Jetzt kommt in einer Endlosschleife folgende Ausgabe:</p>
<pre><code class="language-cpp">x = 55 ist kleiner als y = 56
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2261466</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2261466</guid><dc:creator><![CDATA[silent_max]]></dc:creator><pubDate>Wed, 17 Oct 2012 18:10:47 GMT</pubDate></item><item><title><![CDATA[Reply to while Schleife mit continue und break on Wed, 17 Oct 2012 18:12:21 GMT]]></title><description><![CDATA[<p>silent_max schrieb:</p>
<blockquote>
<p>Ersteinmal Danke für Deine schnelle Antwort.</p>
<p>Den Fehler hat es behoben.</p>
<p>Jedoch ist jetzt ein neuer Fehler aufgetreten, den ich nicht sehe.</p>
<p>Jetzt kommt in einer Endlosschleife folgende Ausgabe:</p>
<pre><code class="language-cpp">x = 55 ist kleiner als y = 56
</code></pre>
</blockquote>
<p>Wieso wundert dich das? 55 ist nunmal kleiner als 56. Und beide sind kleiner als 100. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2261468</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2261468</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Wed, 17 Oct 2012 18:12:21 GMT</pubDate></item><item><title><![CDATA[Reply to while Schleife mit continue und break on Wed, 17 Oct 2012 18:14:35 GMT]]></title><description><![CDATA[<p>Weil ich eigentlich gedacht habe, dass durch die Continue Anweisung zurück gesprungen wird und ich wieder zwei Zahlen eingeben kann...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2261469</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2261469</guid><dc:creator><![CDATA[silent_max]]></dc:creator><pubDate>Wed, 17 Oct 2012 18:14:35 GMT</pubDate></item><item><title><![CDATA[Reply to while Schleife mit continue und break on Wed, 17 Oct 2012 18:17:39 GMT]]></title><description><![CDATA[<p>silent_max schrieb:</p>
<blockquote>
<p>Weil ich eigentlich gedacht habe, dass durch die Continue Anweisung zurück gesprungen wird und ich wieder zwei Zahlen eingeben kann...</p>
</blockquote>
<p>Achso. Nein. Da hast du was falsch verstanden. continue leitet den nächsten Schleifendurchgang ein. Du landest also in Zeile 13. continue ist in dem Fall sogar total überflüssig, weil es die letzte Anweisung deiner Schleife ist. Du landest danach sowieso wieder am Schleifenanfang.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2261471</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2261471</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Wed, 17 Oct 2012 18:17:39 GMT</pubDate></item><item><title><![CDATA[Reply to while Schleife mit continue und break on Wed, 17 Oct 2012 18:23:34 GMT]]></title><description><![CDATA[<p>Achso...</p>
<p>Sorry, dass ich so frage, aber wie muss ich das Programm umschreiben, damit ich erneut Zahlen für x und y eingeben kann? Weil so war das Programm eigentlich gedacht, dass die Eingabe von x und y verglichen wird, welche Zahl größer ist und dann zurück springt, damit ich erneut für x und y Zahlen eingeben kann. Abbruckbedingung soll die Eingabe von 101 sein.</p>
<p>Weil auch wenn ich das &quot;conitune&quot; weg lasse, kommt immer noch die Endlosschleife.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2261474</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2261474</guid><dc:creator><![CDATA[silent_max]]></dc:creator><pubDate>Wed, 17 Oct 2012 18:23:34 GMT</pubDate></item><item><title><![CDATA[Reply to while Schleife mit continue und break on Wed, 17 Oct 2012 18:28:00 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int main()
{
   float x, y;

   while((x&lt;=100)&amp;&amp;(y&lt;=100))
   {
		cout &lt;&lt; &quot;Geben Sie zwei Zahlen zwischen 0 und 100 ein!&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;x:&quot;;
		cin  &gt;&gt; x;
		cout &lt;&lt; &quot;y:&quot;;
		cin  &gt;&gt; y;

		if(x&lt;y)
		{
			cout &lt;&lt; &quot;x = &quot; &lt;&lt; x &lt;&lt; &quot; ist kleiner als y = &quot; &lt;&lt; y &lt;&lt; endl;
		}
		if(y&lt;x)
		{
			cout &lt;&lt; &quot;y = &quot; &lt;&lt; y &lt;&lt; &quot; ist kleiner als x = &quot; &lt;&lt; x &lt;&lt; endl;
		}
		if(x &gt; 100 ||y &gt; 100)
		{
			cout &lt;&lt; &quot;Abbruch!&quot; &lt;&lt; endl;
			break;
		}
   }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2261476</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2261476</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Wed, 17 Oct 2012 18:28:00 GMT</pubDate></item><item><title><![CDATA[Reply to while Schleife mit continue und break on Wed, 17 Oct 2012 18:34:41 GMT]]></title><description><![CDATA[<p><code>continue</code> ist eigentlich nur eine seltsame Schreibweise für if bzw. if-else:</p>
<pre><code class="language-cpp">for(int i=1; i&lt;20; ++i)
	{
		if( i%2!=0 )
			continue;

		// Ich will nur mit geraden Zahlen arbeiten
		// Mache dies
		// Mache das
		// ...
	}
</code></pre>
<p>Das Gleiche wie:</p>
<pre><code class="language-cpp">for(int i=1; i&lt;20; ++i)
	{
		if( i%2==0 )
		{
			// Ich will nur mit geraden Zahlen arbeiten
			// Mache dies
			// Mache das
			// ...
		}
	}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2261481</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2261481</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Wed, 17 Oct 2012 18:34:41 GMT</pubDate></item><item><title><![CDATA[Reply to while Schleife mit continue und break on Wed, 17 Oct 2012 18:35:48 GMT]]></title><description><![CDATA[<p>Sorry, heute sehe ich gar nichts mehr.</p>
<p>Genau - abgesehen von &quot;return 0&quot; - Deinen Code hatte ich, nachdem ich die Continue Anweisung rausgehauen habe und es kommt immer noch eine Endlosschleife.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2261482</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2261482</guid><dc:creator><![CDATA[silent_max]]></dc:creator><pubDate>Wed, 17 Oct 2012 18:35:48 GMT</pubDate></item><item><title><![CDATA[Reply to while Schleife mit continue und break on Wed, 17 Oct 2012 18:40:04 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int main()
{
	float x, y;
	do
	{
        cout &lt;&lt; &quot;Geben Sie zwei Zahlen zwischen 0 und 100 ein!&quot; &lt;&lt; endl;
        cout &lt;&lt; &quot;x:&quot;;
        cin  &gt;&gt; x;
        cout &lt;&lt; &quot;y:&quot;;
        cin  &gt;&gt; y;

		if(x&lt;y)
        {
            cout &lt;&lt; &quot;x = &quot; &lt;&lt; x &lt;&lt; &quot; ist kleiner als y = &quot; &lt;&lt; y &lt;&lt; endl;
        }
        if(y&lt;x)
        {
            cout &lt;&lt; &quot;y = &quot; &lt;&lt; y &lt;&lt; &quot; ist kleiner als x = &quot; &lt;&lt; x &lt;&lt; endl;
        }
        if(x &gt; 100 ||y &gt; 100)
        {
            cout &lt;&lt; &quot;Abbruch!&quot; &lt;&lt; endl;
        }
	}while( (x&lt;=100) &amp;&amp; (y&lt;=100) );
}
</code></pre>
<p>Du suchst sowas. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";-)"
      alt="😉"
    /> Das ist ein Anwendungsfall für do-while.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2261483</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2261483</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Wed, 17 Oct 2012 18:40:04 GMT</pubDate></item><item><title><![CDATA[Reply to while Schleife mit continue und break on Wed, 17 Oct 2012 18:41:21 GMT]]></title><description><![CDATA[<p>Beachte: Die Schleife umfasst auch die Eingabe der Zahlen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2261484</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2261484</guid><dc:creator><![CDATA[DirkB]]></dc:creator><pubDate>Wed, 17 Oct 2012 18:41:21 GMT</pubDate></item><item><title><![CDATA[Reply to while Schleife mit continue und break on Wed, 17 Oct 2012 18:51:16 GMT]]></title><description><![CDATA[<p>Ok.</p>
<p>Jetzt funktioniert es auch.</p>
<p>Aber bei do...while Schleifen bin ich noch nicht angelangt in meinem Buch, kommt aber demnächst.</p>
<p>Vielen Dank ersteinmal für Deine Tipps, habe mich sehr weitergebracht.</p>
<p>Gruß Max</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2261486</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2261486</guid><dc:creator><![CDATA[silent_max]]></dc:creator><pubDate>Wed, 17 Oct 2012 18:51:16 GMT</pubDate></item><item><title><![CDATA[Reply to while Schleife mit continue und break on Wed, 17 Oct 2012 18:53:43 GMT]]></title><description><![CDATA[<p>silent_max schrieb:</p>
<blockquote>
<p>Ok.</p>
<p>Jetzt funktioniert es auch.</p>
<p>Aber bei do...while Schleifen bin ich noch nicht angelangt in meinem Buch, kommt aber demnächst.</p>
<p>Vielen Dank ersteinmal für Deine Tipps, habe mich sehr weitergebracht.</p>
<p>Gruß Max</p>
</blockquote>
<p>Wenn es um Schleifen geht müssen dir die Begriffe fußgesteuert und kopfgesteuert bekannt sein und was man darunter versteht. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2261487</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2261487</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Wed, 17 Oct 2012 18:53:43 GMT</pubDate></item><item><title><![CDATA[Reply to while Schleife mit continue und break on Wed, 17 Oct 2012 19:04:21 GMT]]></title><description><![CDATA[<p>Du kannst das auch mit der while-Schleife machen.<br />
Nur solltest du dabei beachten, das du den Variablen vorher auch Wert zuweist (initialisierst).</p>
<pre><code class="language-cpp">float x=0, y=0;

   while((x&lt;=100)&amp;&amp;(y&lt;=100))
   {
        cout &lt;&lt; &quot;Geben Si...
</code></pre>
<p>Wenn du es ohne Initialisierung machst, sollte der Compiler auch eine Warnung ausgeben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2261492</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2261492</guid><dc:creator><![CDATA[DirkB]]></dc:creator><pubDate>Wed, 17 Oct 2012 19:04:21 GMT</pubDate></item></channel></rss>