<?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[Schleifen funktionieren nicht so wie ich will]]></title><description><![CDATA[<p>Hallo liebe Gemeinde.</p>
<p>Ich habe folgenden Programmcode aufgesetzt:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

int main()
{
  int number;

  cout &lt;&lt; &quot;Schleifen im Vergleich!&quot; &lt;&lt; endl;
  cout &lt;&lt; endl;
  cout &lt;&lt; &quot;(1) for - Schleife&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;(2) do...while - Schleife&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;(3) while - Schleife&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;(0) Abbruch!&quot; &lt;&lt; endl;
  cin  &gt;&gt; number;

  switch(number)
  {
   case 1:
     cout &lt;&lt; &quot;Sie haben sich fuer eine for - Schleife entschieden!&quot; &lt;&lt; endl;
     cout &lt;&lt; &quot;Jetzt wird die for - Schleife ausgefuehrt!&quot; &lt;&lt; endl;
     for (int i=0; i &lt; 1000; i++)
     {
       cout &lt;&lt; &quot;Wie oft soll Hallo ausgegeben werden?&quot; &lt;&lt; endl;
       cin  &gt;&gt; i;
       cout &lt;&lt; &quot;Hallo!&quot; &lt;&lt; endl;
     }
     break;
    case 2:
     int k;
     cout &lt;&lt; &quot;Sie haben sich fuer eine do...while - Schleife entschieden&quot;&lt;&lt;endl;
     cout &lt;&lt; &quot;Jetzt wird die do...while - Schleife ausgefuehrt!&quot; &lt;&lt; endl;
     cout &lt;&lt; &quot;Abbruchbedinung ist die Ziffer 0&quot; &lt;&lt; endl;
     do
     {
       cout &lt;&lt; &quot;Wie oft soll Hallo ausgegeben werden?&quot; &lt;&lt; endl;
       cin  &gt;&gt; k;
       if (k!=0)
       {
         cout &lt;&lt; &quot;Hallo&quot; &lt;&lt; endl;
       }
       else
       {
         cout &lt;&lt; &quot;Abbruch!&quot; &lt;&lt; endl;
       }
     }while(k!=0);
     break;
    case 3:
     int j;
     cout &lt;&lt; &quot;Sie haben sich fuer eine while - Schleife entschieden!&quot; &lt;&lt; endl;
     cout &lt;&lt; &quot;Jetzt wird die while - Schleife ausgefuehrt!&quot; &lt;&lt; endl;
     cout &lt;&lt; &quot;Abbruchbedingung ist die Ziffer 0!&quot; &lt;&lt; endl;
     while(j!=0)
     {
       cout &lt;&lt; &quot;Wie oft soll Hallo ausgegeben werden?&quot; &lt;&lt; endl;
       cin  &gt;&gt; j;
       if (j!=0)
       {
         cout &lt;&lt; &quot;Hallo&quot; &lt;&lt; endl;
       }
       else 
       {
         cout &lt;&lt; &quot;Abbruch!&quot; &lt;&lt; endl;
       }
     }
     break;
    case 0:
     cout &lt;&lt; &quot;Abbruch!&quot; &lt;&lt; endl;
     break;
  }
  return 0;
}
</code></pre>
<p>Nun zu den Fehlern:</p>
<p>1.) Wenn ich bei der Menüauswahl 1, also die for-Schleife, aussuche kommt die<br />
Fehlermeldung &quot;Run-Time Check Failure #3 - The variable 'i' is being<br />
used without being initialized.&quot;<br />
Ich sehe den Fehler nicht, da ich dachte, dass ich die Variable i in der<br />
for - Schleife richtig deklariert und somit verwendet hätte.</p>
<p>2.) Bei den anderen beiden Schleifen wird &quot;Hallo&quot; nur einmal ausgegeben, egal<br />
welche Zahl ich eingebe. Wo liegt dort den Fehler? Ich sehe ihn nicht...</p>
<p>Ich bedanke mich schon einmal im Voraus für die Antworten.</p>
<p>Gruß</p>
<p>Max</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/310065/schleifen-funktionieren-nicht-so-wie-ich-will</link><generator>RSS for Node</generator><lastBuildDate>Wed, 05 Aug 2026 02:33:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/310065.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 02 Nov 2012 18:00:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 19:36:00 GMT]]></title><description><![CDATA[<p>Hallo liebe Gemeinde.</p>
<p>Ich habe folgenden Programmcode aufgesetzt:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

int main()
{
  int number;

  cout &lt;&lt; &quot;Schleifen im Vergleich!&quot; &lt;&lt; endl;
  cout &lt;&lt; endl;
  cout &lt;&lt; &quot;(1) for - Schleife&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;(2) do...while - Schleife&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;(3) while - Schleife&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;(0) Abbruch!&quot; &lt;&lt; endl;
  cin  &gt;&gt; number;

  switch(number)
  {
   case 1:
     cout &lt;&lt; &quot;Sie haben sich fuer eine for - Schleife entschieden!&quot; &lt;&lt; endl;
     cout &lt;&lt; &quot;Jetzt wird die for - Schleife ausgefuehrt!&quot; &lt;&lt; endl;
     for (int i=0; i &lt; 1000; i++)
     {
       cout &lt;&lt; &quot;Wie oft soll Hallo ausgegeben werden?&quot; &lt;&lt; endl;
       cin  &gt;&gt; i;
       cout &lt;&lt; &quot;Hallo!&quot; &lt;&lt; endl;
     }
     break;
    case 2:
     int k;
     cout &lt;&lt; &quot;Sie haben sich fuer eine do...while - Schleife entschieden&quot;&lt;&lt;endl;
     cout &lt;&lt; &quot;Jetzt wird die do...while - Schleife ausgefuehrt!&quot; &lt;&lt; endl;
     cout &lt;&lt; &quot;Abbruchbedinung ist die Ziffer 0&quot; &lt;&lt; endl;
     do
     {
       cout &lt;&lt; &quot;Wie oft soll Hallo ausgegeben werden?&quot; &lt;&lt; endl;
       cin  &gt;&gt; k;
       if (k!=0)
       {
         cout &lt;&lt; &quot;Hallo&quot; &lt;&lt; endl;
       }
       else
       {
         cout &lt;&lt; &quot;Abbruch!&quot; &lt;&lt; endl;
       }
     }while(k!=0);
     break;
    case 3:
     int j;
     cout &lt;&lt; &quot;Sie haben sich fuer eine while - Schleife entschieden!&quot; &lt;&lt; endl;
     cout &lt;&lt; &quot;Jetzt wird die while - Schleife ausgefuehrt!&quot; &lt;&lt; endl;
     cout &lt;&lt; &quot;Abbruchbedingung ist die Ziffer 0!&quot; &lt;&lt; endl;
     while(j!=0)
     {
       cout &lt;&lt; &quot;Wie oft soll Hallo ausgegeben werden?&quot; &lt;&lt; endl;
       cin  &gt;&gt; j;
       if (j!=0)
       {
         cout &lt;&lt; &quot;Hallo&quot; &lt;&lt; endl;
       }
       else 
       {
         cout &lt;&lt; &quot;Abbruch!&quot; &lt;&lt; endl;
       }
     }
     break;
    case 0:
     cout &lt;&lt; &quot;Abbruch!&quot; &lt;&lt; endl;
     break;
  }
  return 0;
}
</code></pre>
<p>Nun zu den Fehlern:</p>
<p>1.) Wenn ich bei der Menüauswahl 1, also die for-Schleife, aussuche kommt die<br />
Fehlermeldung &quot;Run-Time Check Failure #3 - The variable 'i' is being<br />
used without being initialized.&quot;<br />
Ich sehe den Fehler nicht, da ich dachte, dass ich die Variable i in der<br />
for - Schleife richtig deklariert und somit verwendet hätte.</p>
<p>2.) Bei den anderen beiden Schleifen wird &quot;Hallo&quot; nur einmal ausgegeben, egal<br />
welche Zahl ich eingebe. Wo liegt dort den Fehler? Ich sehe ihn nicht...</p>
<p>Ich bedanke mich schon einmal im Voraus für die Antworten.</p>
<p>Gruß</p>
<p>Max</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266676</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266676</guid><dc:creator><![CDATA[silent_max]]></dc:creator><pubDate>Fri, 02 Nov 2012 19:36:00 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 18:05:46 GMT]]></title><description><![CDATA[<p>Zu 1): Ist doch klar, du musst <code>i</code> mit <code>= 0</code> initialisieren.<br />
Übrigens benutzt du auch einige andere Variablen uninitialisiert. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/26a0.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--warning"
      title=":warning:"
      alt="⚠"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266677</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266677</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Fri, 02 Nov 2012 18:05:46 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 18:06:03 GMT]]></title><description><![CDATA[<p>1. Deklariert, Definiert, alles klar. Aber eben nicht initialisiert. <code>int i = 0;</code> willst du wohl haben.<br />
2.</p>
<ol>
<li>Die Abfrage nach der Anzahl der Durchläufe steht ja auch innerhalb der Schleife!</li>
<li>Wenn du die Abfrage vorziehst wirst du das Problem bekommen, dass die Laufvariablen nicht verändert werden, du also eine Endlosschleife bekommen wirst. Du willst also vermutlich irgendwo während eines Durchlaufs die Laufvariablen um 1 erniedrigen.</li>
</ol>
]]></description><link>https://www.c-plusplus.net/forum/post/2266678</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266678</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Fri, 02 Nov 2012 18:06:03 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 18:10:43 GMT]]></title><description><![CDATA[<p>Vor der Abfrage einer Variablen, solltes du ihr einen Wert zuweisen.</p>
<p>Bei deinem Fall 1 passiert das schon bei i&lt;1000.<br />
Eine Definition ist keine Initialisierung. Eine Deklaration schon gar nicht.</p>
<p>Ich vermisse die Definition von k. Außerdem fehlen Klammern. Dann ist das nicht das Programm das du compilierst.<br />
Also erübrigt sich jede weitere Fehlersuche.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266679</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266679</guid><dc:creator><![CDATA[DirkB]]></dc:creator><pubDate>Fri, 02 Nov 2012 18:10:43 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 18:21:03 GMT]]></title><description><![CDATA[<p>scnr, wo bleibt der hide-Button? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

int main()
{
	cout	&lt;&lt; &quot;Schleifen im Vergleich!\n\n&quot;
			&lt;&lt; &quot;(1) for - Schleife\n&quot;
			&lt;&lt; &quot;(2) do...while - Schleife\n&quot;
			&lt;&lt; &quot;(3) while - Schleife\n&quot;
			&lt;&lt; &quot;(0) Abbruch!\n&quot;;

	int number = -1;
	cin &gt;&gt; number;

	switch( number ) {

		case 1: {

			cout	&lt;&lt; &quot;Sie haben sich fuer eine for - Schleife entschieden!\n&quot;
					&lt;&lt; &quot;Jetzt wird die for - Schleife ausgefuehrt!\n&quot;
					&lt;&lt; &quot;Wie oft soll Hallo ausgegeben werden?\n&quot;;

			int i = 0;
			cin &gt;&gt; i;

			if( !i ) {

				cout &lt;&lt; &quot;Abbruch!\n&quot;;
				break;
			}

			for ( ; i; --i ) cout &lt;&lt; &quot;Hallo!\n&quot;;

			break;
		}

		case 2: {

			cout	&lt;&lt; &quot;Sie haben sich fuer eine do...while - Schleife entschieden\n&quot;
					&lt;&lt; &quot;Jetzt wird die do...while - Schleife ausgefuehrt!\n&quot;
					&lt;&lt; &quot;Abbruchbedinung ist die Ziffer 0\n&quot;
					&lt;&lt; &quot;Wie oft soll Hallo ausgegeben werden?\n&quot;;

			int k = 0;
			cin &gt;&gt; k;

			do {

				if( k ) cout &lt;&lt; &quot;Hallo\n&quot;;
				else cout &lt;&lt; &quot;Abbruch!\n&quot;;

			} while( k-- );

			break;
		}

		case 3:
		{
			cout	&lt;&lt; &quot;Sie haben sich fuer eine while - Schleife entschieden!\n&quot;
					&lt;&lt; &quot;Jetzt wird die while - Schleife ausgefuehrt!\n&quot;
					&lt;&lt; &quot;Abbruchbedingung ist die Ziffer 0!\n&quot;
					&lt;&lt; &quot;Wie oft soll Hallo ausgegeben werden?\n&quot;;

			int j;
			cin  &gt;&gt; j;

			++j;

			while( j-- ) {

				if( j ) cout &lt;&lt; &quot;Hallo\n&quot;;
				else cout &lt;&lt; &quot;Abbruch!\n&quot;;
			}

			break;
		}

		case 0:
			cout &lt;&lt; &quot;Abbruch!\n&quot;;
			break;

		default:
			cout &lt;&lt; &quot;Eingabefehler!\n&quot;;
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2266683</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266683</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Fri, 02 Nov 2012 18:21:03 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 18:21:23 GMT]]></title><description><![CDATA[<p>Ersteinmal Danke für die Antworten.</p>
<p>Sorry, ich habe im obigen Code die Zeile</p>
<pre><code class="language-cpp">int k;
</code></pre>
<p>vergessen.</p>
<p>Werde ich gleich ausbessern.</p>
<p>Ich habe jetzt die for-Schleife optimiert... Jetzt kommt wie bei den anderen beiden Schleifen zwar die Frage &quot;Wie oft soll Hallo ausgegeben werden?&quot;, aber auch da kann ich jede beliebige Zahl eingeben und &quot;Hallo&quot; wird bloß einmal ausgeführt.</p>
<p>Was mache ich falsch bzw. welchen Denkfehler habe ich??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266684</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266684</guid><dc:creator><![CDATA[silent_max]]></dc:creator><pubDate>Fri, 02 Nov 2012 18:21:23 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 18:24:39 GMT]]></title><description><![CDATA[<p>Das cin steht <strong>in</strong> der Schleife.</p>
<p>Also musst du auch entsprechen oft einen Wert eingeben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266687</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266687</guid><dc:creator><![CDATA[DirkB]]></dc:creator><pubDate>Fri, 02 Nov 2012 18:24:39 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 18:25:33 GMT]]></title><description><![CDATA[<p>Ohne Frage ist es sinnvoller den Wert <strong>vor</strong> der Schleife abzufragen. <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/2266688</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266688</guid><dc:creator><![CDATA[DirkB]]></dc:creator><pubDate>Fri, 02 Nov 2012 18:25:33 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 18:29:06 GMT]]></title><description><![CDATA[<p>Nun habe ich die besagte Endlosschleife bei Menüpunkt 2 und 3...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266690</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266690</guid><dc:creator><![CDATA[silent_max]]></dc:creator><pubDate>Fri, 02 Nov 2012 18:29:06 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 18:29:14 GMT]]></title><description><![CDATA[<p>Poste vollständigen Code per copy and paste!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266691</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266691</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Fri, 02 Nov 2012 18:29:14 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 18:33:19 GMT]]></title><description><![CDATA[<p>Kann ich nicht machen, da ich gerade bei einem Freund bin und über seinen PC im Internet bin und der Code auf meinem Netbook ist...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266694</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266694</guid><dc:creator><![CDATA[silent_max]]></dc:creator><pubDate>Fri, 02 Nov 2012 18:33:19 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 18:53:20 GMT]]></title><description><![CDATA[<p>Ich habe nochmal über den Code drüber geschaut ... der müsste jetzt soweit passen.</p>
<p>Ich sehe aber dennoch den Fehler nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266703</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266703</guid><dc:creator><![CDATA[silent_max]]></dc:creator><pubDate>Fri, 02 Nov 2012 18:53:20 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 19:14:35 GMT]]></title><description><![CDATA[<p>Liest du auch die Hinweise durch? Alle?</p>
<p>Es ist allerdings auch blöd den Code auf der ersten Seite zu ändern, ohne es anzukündigen.</p>
<p>Wie oft gibst du Werte ein?<br />
Oder anders gefragt:<br />
Wie oft erscheint das &quot;Wie oft soll Hallo ausgegeben werden?&quot; ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266710</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266710</guid><dc:creator><![CDATA[DirkB]]></dc:creator><pubDate>Fri, 02 Nov 2012 19:14:35 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 19:24:58 GMT]]></title><description><![CDATA[<p>silent_max schrieb:</p>
<blockquote>
<p>[...] müsste jetzt soweit passen.</p>
</blockquote>
<p>Njet. Ich spendier' noch ein Semikolon am Ende von Zeile 45 - dann kompiliert das Ding wenigstens.<br />
<code>int i</code> im <code>case 1</code> wird immer noch uninitialisiert verwendet.<br />
Du scheinst keinen der gemachten Vorschläge bzw. Erleuterungen beachtet zu haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266713</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266713</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Fri, 02 Nov 2012 19:24:58 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 19:25:35 GMT]]></title><description><![CDATA[<p>Es erscheint einmal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266714</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266714</guid><dc:creator><![CDATA[silent_max]]></dc:creator><pubDate>Fri, 02 Nov 2012 19:25:35 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 19:29:23 GMT]]></title><description><![CDATA[<p>Bei welcher Auswahl? <code>1</code> für &quot;for-Schleife&quot;? Reiner Zufall.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266716</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266716</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Fri, 02 Nov 2012 19:29:23 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 19:33:05 GMT]]></title><description><![CDATA[<p>Bei welchen Eingabewerten?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266717</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266717</guid><dc:creator><![CDATA[DirkB]]></dc:creator><pubDate>Fri, 02 Nov 2012 19:33:05 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 20:05:45 GMT]]></title><description><![CDATA[<p>Also der gesamte Code sieht jetzt so aus:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

int main()
{
 int number;

 cout &lt;&lt; &quot;Schleifen im Vergleich!&quot; &lt;&lt; endl;
 cout &lt;&lt; endl;
 cout &lt;&lt; &quot;Welche Schleife wollen Sie ausfuehren?&quot; &lt;&lt; endl;
 cout &lt;&lt; &quot;(1) for - Schleife&quot; &lt;&lt; endl;
 cout &lt;&lt; &quot;(2) do ... while - Schleife&quot; &lt;&lt; endl;
 cout &lt;&lt; &quot;(3) while - Schleife&quot; &lt;&lt; endl;
 cout &lt;&lt; &quot;(0) Abbruch!&quot; &lt;&lt; endl;
 cin  &gt;&gt; number;

 switch (number)
 {
  case 1:
   int i;
   cout &lt;&lt; &quot;Sie haben sich fuer eine for - Schleife entschieden!&quot; &lt;&lt; endl;
   cout &lt;&lt; &quot;Jetzt wird die for - Schleife ausgefuehrt!&quot; &lt;&lt; endl;
   cout &lt;&lt; &quot;Wie oft soll Hallo ausgegeben werden?&quot;&lt;&lt; endl;
   cin  &gt;&gt; i;
   for (; i &lt;1000; i++)
   {
    cout &lt;&lt; &quot;Hallo&quot;;
   }
   break;
  case 2:
   int k;
   cout &lt;&lt; &quot;Sie haben sich fuer eine do...while - Schleife entschieden!&quot;&lt;&lt; endl;
   cout &lt;&lt; &quot;Jetzt wird die do...while - Schleife ausgefuehrt!&quot; &lt;&lt; endl;
   cout &lt;&lt; &quot;Abbruchbedingung ist die Ziffer 0&quot; &lt;&lt; endl;
   cout &lt;&lt; &quot;Wie oft soll Hallo ausgegeben werden?&quot; &lt;&lt; endl;
   cin  &gt;&gt; k;
   do
   {
    if (k!=0)
      cout &lt;&lt; &quot;Hallo&quot;;
    else
      cout &lt;&lt; &quot;Abbruch;
   }while(k!=0);
   break;
  case 3:
   int j;
   cout &lt;&lt; &quot;Sie haben sich fuer eine while - Schleife entschieden!&quot; &lt;&lt; endl;
   cout &lt;&lt; &quot;Jetzt wird die while - Schleife ausgefuehrt!&quot; &lt;&lt; endl;
   cout &lt;&lt; &quot;Abbruchbedingung ist die Ziffer 0!&quot; &lt;&lt; endl;
   cout &lt;&lt; &quot;Wie oft soll Hallo ausgegeben werden?&quot; &lt;&lt; endl;
   cin  &gt;&gt; j;

   while(j!=0)
   {
    if(j!=0)
     cout &lt;&lt; &quot;Hallo&quot; &lt;&lt; endl;
    else 
     cout &lt;&lt; &quot;Abbruch!&quot; &lt;&lt; endl;
   }    
   break;
  case 0:
   cout &lt;&lt; &quot;Abbruch!&quot; &lt;&lt; endl;
   break;
  } 
 return 0;
}
</code></pre>
<p>Bei Menüauswahl 1 werde ich zwar gefragt, wie oft &quot;Hallo&quot; ausgegeben werden soll, aber die Schleife läuft wohl bis 1000 durch.</p>
<p>Bei Menüauswahl 2 werde ich zwar gefragt, wie oft &quot;Hallo&quot; ausgegeben werden soll, aber es erscheint eine Endlosschleife, wie SeppJ schon geschrieben hat.</p>
<p>Bei Menüauswahl 3 werde ich zwar gefragt, wie oft &quot;Hallo&quot; ausgegeben werden soll, aber es erscheint eine Endlosschleife, wie SeppJ schon geschrieben hat.</p>
<p>Bloß wo liegt der Fehler???????????????????????</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266724</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266724</guid><dc:creator><![CDATA[silent_max]]></dc:creator><pubDate>Fri, 02 Nov 2012 20:05:45 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 20:01:54 GMT]]></title><description><![CDATA[<p>silent_max schrieb:</p>
<blockquote>
<p>Also der gesamte Code sieht jetzt so aus: [...]</p>
</blockquote>
<p>Glaube ich nicht.</p>
<pre><code>1&gt;main.cpp(28): error C2143: syntax error : missing ';' before '}'
1&gt;main.cpp(42): error C2001: newline in constant
1&gt;main.cpp(43): error C2143: syntax error : missing ';' before '}'
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2266726</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266726</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Fri, 02 Nov 2012 20:01:54 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 20:06:03 GMT]]></title><description><![CDATA[<p>Bei 1. fängst du bei i an zu zählen. Wenn du für i mal 998 eingibst, kommen weniger Ausgaben.</p>
<p>Zu 2. und 3.<br />
Wenn du zählen willst, musst du einen Wert auch mal verändern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266727</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266727</guid><dc:creator><![CDATA[DirkB]]></dc:creator><pubDate>Fri, 02 Nov 2012 20:06:03 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 20:06:20 GMT]]></title><description><![CDATA[<p>Habe es ausgebessert!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266728</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266728</guid><dc:creator><![CDATA[silent_max]]></dc:creator><pubDate>Fri, 02 Nov 2012 20:06:20 GMT</pubDate></item><item><title><![CDATA[Reply to Schleifen funktionieren nicht so wie ich will on Fri, 02 Nov 2012 21:09:07 GMT]]></title><description><![CDATA[<p>mhm.</p>
<pre><code>1&gt;main.cpp(42): error C2001: newline in constant
1&gt;main.cpp(43): error C2143: syntax error : missing ';' before '}'
</code></pre>
<p>Hast Du keinen Compiler!?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266752</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266752</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Fri, 02 Nov 2012 21:09:07 GMT</pubDate></item></channel></rss>