<?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]]></title><description><![CDATA[<p><strong>[gelöst]</strong></p>
<p>Hallo,<br />
ich möchte wissen, wie ich die while-Schleife über eine switch-Anweisung beenden kann. Mit if(c=='4') break; geht es ja aber ich möchte das nicht mit if machen. Dafür habe ich ein nutzloses Programm geschrieben um dies auszuprobieren:</p>
<pre><code class="language-cpp">// main.cpp

#include &quot;functions.h&quot;
#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
using namespace std;

int main(void){
	int zahl;
	char c;

	while(true){
		cout &lt;&lt; &quot;Wählen Sie (1-4) \n&quot;&lt;&lt; endl
			 &lt;&lt; &quot;Berechnung der Fakultaet (1) \n&quot; &lt;&lt; endl
			 &lt;&lt; &quot;Zahl verdoppeln          (2) \n&quot; &lt;&lt; endl
			 &lt;&lt; &quot;Negative Zahl ausgeben   (3) \n&quot; &lt;&lt; endl
			 &lt;&lt; &quot;Programm beenden         (4) \n&quot; &lt;&lt; endl
			 &lt;&lt; &quot;Welche Option wollen Sie aufrufen: \n&quot;;

		cin &gt;&gt; c;

		switch(c)
		{
			case '1':
				cout &lt;&lt; &quot;Geben Sie eine Zahl ein:&quot;;
				cin &gt;&gt; zahl;
				cout &lt;&lt; &quot;\nDie Fakultaet ist: &quot; &lt;&lt; fac(zahl) &lt;&lt; &quot;\n\n&quot;;
				break;
			case '2':
				cout &lt;&lt; &quot;Geben Sie eine Zahl ein:&quot;;
				cin &gt;&gt; zahl;
				cout &lt;&lt; &quot;\nVedopplung: &quot; &lt;&lt; verdoppeln(zahl) &lt;&lt; &quot;\n\n&quot;;
				break;
			case '3':
				cout &lt;&lt; &quot;Geben Sie eine Zahl ein:&quot;;
				cin &gt;&gt; zahl;
				cout &lt;&lt; &quot;\nNegative Zahl: &quot; &lt;&lt; neg(zahl) &lt;&lt; &quot;\n\n&quot;;
				break;
			case '4':
				break; // SO GEHT ES NICHT
		}
		if(c=='4')
			break;        // SO ABER SCHON 
	}

	system(&quot;PAUSE&quot;);
	return EXIT_SUCCESS;
}
</code></pre>
<p>Ich hoffe ihr wisst eine Lösung zu dem &quot;Problem&quot;.</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/265955/while-schleife</link><generator>RSS for Node</generator><lastBuildDate>Thu, 03 Sep 2026 16:41:32 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/265955.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 01 May 2010 18:03:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to while-Schleife on Sat, 01 May 2010 18:18:37 GMT]]></title><description><![CDATA[<p><strong>[gelöst]</strong></p>
<p>Hallo,<br />
ich möchte wissen, wie ich die while-Schleife über eine switch-Anweisung beenden kann. Mit if(c=='4') break; geht es ja aber ich möchte das nicht mit if machen. Dafür habe ich ein nutzloses Programm geschrieben um dies auszuprobieren:</p>
<pre><code class="language-cpp">// main.cpp

#include &quot;functions.h&quot;
#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
using namespace std;

int main(void){
	int zahl;
	char c;

	while(true){
		cout &lt;&lt; &quot;Wählen Sie (1-4) \n&quot;&lt;&lt; endl
			 &lt;&lt; &quot;Berechnung der Fakultaet (1) \n&quot; &lt;&lt; endl
			 &lt;&lt; &quot;Zahl verdoppeln          (2) \n&quot; &lt;&lt; endl
			 &lt;&lt; &quot;Negative Zahl ausgeben   (3) \n&quot; &lt;&lt; endl
			 &lt;&lt; &quot;Programm beenden         (4) \n&quot; &lt;&lt; endl
			 &lt;&lt; &quot;Welche Option wollen Sie aufrufen: \n&quot;;

		cin &gt;&gt; c;

		switch(c)
		{
			case '1':
				cout &lt;&lt; &quot;Geben Sie eine Zahl ein:&quot;;
				cin &gt;&gt; zahl;
				cout &lt;&lt; &quot;\nDie Fakultaet ist: &quot; &lt;&lt; fac(zahl) &lt;&lt; &quot;\n\n&quot;;
				break;
			case '2':
				cout &lt;&lt; &quot;Geben Sie eine Zahl ein:&quot;;
				cin &gt;&gt; zahl;
				cout &lt;&lt; &quot;\nVedopplung: &quot; &lt;&lt; verdoppeln(zahl) &lt;&lt; &quot;\n\n&quot;;
				break;
			case '3':
				cout &lt;&lt; &quot;Geben Sie eine Zahl ein:&quot;;
				cin &gt;&gt; zahl;
				cout &lt;&lt; &quot;\nNegative Zahl: &quot; &lt;&lt; neg(zahl) &lt;&lt; &quot;\n\n&quot;;
				break;
			case '4':
				break; // SO GEHT ES NICHT
		}
		if(c=='4')
			break;        // SO ABER SCHON 
	}

	system(&quot;PAUSE&quot;);
	return EXIT_SUCCESS;
}
</code></pre>
<p>Ich hoffe ihr wisst eine Lösung zu dem &quot;Problem&quot;.</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1891011</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1891011</guid><dc:creator><![CDATA[beuu]]></dc:creator><pubDate>Sat, 01 May 2010 18:18:37 GMT</pubDate></item><item><title><![CDATA[Reply to while-Schleife on Sat, 01 May 2010 18:07:08 GMT]]></title><description><![CDATA[<p>Dafür ist ja die Schleifenbedingung da.</p>
<p>[cpp]<br />
// main.cpp</p>
<p>#include &quot;functions.h&quot;<br />
#include &lt;iostream&gt;<br />
#include &lt;cstdlib&gt;<br />
using namespace std;</p>
<p>int main(void){<br />
int zahl;<br />
char c;<br />
bool schleifenende=false;</p>
<p>while(!schleifenende){<br />
cout &lt;&lt; &quot;Wählen Sie (1-4) \n&quot;&lt;&lt; endl<br />
&lt;&lt; &quot;Berechnung der Fakultaet (1) \n&quot; &lt;&lt; endl<br />
&lt;&lt; &quot;Zahl verdoppeln (2) \n&quot; &lt;&lt; endl<br />
&lt;&lt; &quot;Negative Zahl ausgeben (3) \n&quot; &lt;&lt; endl<br />
&lt;&lt; &quot;Programm beenden (4) \n&quot; &lt;&lt; endl<br />
&lt;&lt; &quot;Welche Option wollen Sie aufrufen: \n&quot;;</p>
<p>cin &gt;&gt; c;</p>
<p>switch(c)<br />
{<br />
case '1':<br />
cout &lt;&lt; &quot;Geben Sie eine Zahl ein:&quot;;<br />
cin &gt;&gt; zahl;<br />
cout &lt;&lt; &quot;\nDie Fakultaet ist: &quot; &lt;&lt; fac(zahl) &lt;&lt; &quot;\n\n&quot;;<br />
break;<br />
case '2':<br />
cout &lt;&lt; &quot;Geben Sie eine Zahl ein:&quot;;<br />
cin &gt;&gt; zahl;<br />
cout &lt;&lt; &quot;\nVedopplung: &quot; &lt;&lt; verdoppeln(zahl) &lt;&lt; &quot;\n\n&quot;;<br />
break;<br />
case '3':<br />
cout &lt;&lt; &quot;Geben Sie eine Zahl ein:&quot;;<br />
cin &gt;&gt; zahl;<br />
cout &lt;&lt; &quot;\nNegative Zahl: &quot; &lt;&lt; neg(zahl) &lt;&lt; &quot;\n\n&quot;;<br />
break;<br />
case '4':<br />
schleifenende=true; // &lt;--<br />
}<br />
}</p>
<p>system(&quot;PAUSE&quot;);<br />
return EXIT_SUCCESS;<br />
}</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1891014</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1891014</guid><dc:creator><![CDATA[player4245]]></dc:creator><pubDate>Sat, 01 May 2010 18:07:08 GMT</pubDate></item><item><title><![CDATA[Reply to while-Schleife on Sat, 01 May 2010 18:18:07 GMT]]></title><description><![CDATA[<p>Danke dir. Wär mir nicht so mit bool eingefallen :). In C würde man dafür eine Zahl nehmen und den wert ändern um die Schleife zu beenden oder?? Was man auch hier machen kann, wobei ich das mit bool besser finde. Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1891020</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1891020</guid><dc:creator><![CDATA[beuu]]></dc:creator><pubDate>Sat, 01 May 2010 18:18:07 GMT</pubDate></item><item><title><![CDATA[Reply to while-Schleife on Sat, 01 May 2010 18:20:59 GMT]]></title><description><![CDATA[<p>beuu schrieb:</p>
<blockquote>
<p>Danke dir. Wär mir nicht so mit bool eingefallen :). In C würde man dafür eine Zahl nehmen und den wert ändern um die Schleife zu beenden oder?? Was man auch hier machen kann, wobei ich das mit bool besser finde. Danke</p>
</blockquote>
<p>In C würde man einen integer als bool'sche Variable nutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1891021</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1891021</guid><dc:creator><![CDATA[Janjan]]></dc:creator><pubDate>Sat, 01 May 2010 18:20:59 GMT</pubDate></item><item><title><![CDATA[Reply to while-Schleife on Sat, 01 May 2010 18:20:27 GMT]]></title><description><![CDATA[<p>Jop in C werden Zahlen als boolsche Ausdrücke interpretiert. 0 ist false und alles ungleich 0 ist true.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1891022</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1891022</guid><dc:creator><![CDATA[player4245]]></dc:creator><pubDate>Sat, 01 May 2010 18:20:27 GMT</pubDate></item><item><title><![CDATA[Reply to while-Schleife on Sat, 01 May 2010 20:53:19 GMT]]></title><description><![CDATA[<p>player4245 schrieb:</p>
<blockquote>
<p>Jop in C werden Zahlen als boolsche Ausdrücke interpretiert. 0 ist false und alles ungleich 0 ist true.</p>
</blockquote>
<p>Und auch das nur, weil es kein bool gibt. In C++ sollte man daher unbedingt bool verwenden. Dafür ist es ja gemacht!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1891113</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1891113</guid><dc:creator><![CDATA[jkljkl]]></dc:creator><pubDate>Sat, 01 May 2010 20:53:19 GMT</pubDate></item></channel></rss>