<?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[Welche der beiden Möglichkeiten ist &amp;quot;saubererer&amp;quot; Code?]]></title><description><![CDATA[<p>Hallo. Ich wollte Euch fragen, was der &quot;bessere&quot; Code von beiden ist:</p>
<p>1. mit einer <code>for</code> -Schleife:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

int main()
{
	char Nochmal = 'n';
	do
	{
	system(&quot;cls&quot;);
	cout &lt;&lt; &quot;Taschenrechner:\nGeben Sie eine Zahl, den Operanden und die andere Zahl ein:\n&quot;;

	double zahl1 = 0.0, zahl2 = 0.0;
	char Operator;

	cin &gt;&gt; zahl1 &gt;&gt; Operator &gt;&gt; zahl2;

	switch(Operator)
	{
	case '*':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1*zahl2 &lt;&lt; endl;
		break;
	case '+':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1+zahl2 &lt;&lt; endl;
		break;
	case '-':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1-zahl2 &lt;&lt; endl;
		break;
	case '/':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1/zahl2 &lt;&lt; endl;
		break;	
	}
	for(;;)
	{
		cout &lt;&lt; &quot;Nochmal? (j/n)&quot;;
		cin &gt;&gt; Nochmal;

		if(Nochmal == 'j' || Nochmal == 'J')
			break;
		else if(Nochmal == 'n' || Nochmal == 'N')
		{
			return EXIT_SUCCESS;
		}
		else
		{
			cout &lt;&lt; &quot;Falsche Eingabe&quot; &lt;&lt; endl;
		}
	}
	}while(1);
}
</code></pre>
<p>2. mit <code>goto</code> :</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

int main()
{
	char Nochmal = 'n';
	do
	{
	system(&quot;cls&quot;);
	cout &lt;&lt; &quot;Taschenrechner:\nGeben Sie eine Zahl, den Operanden und die andere Zahl ein:\n&quot;;

	double zahl1 = 0.0, zahl2 = 0.0;
	char Operator;

	cin &gt;&gt; zahl1 &gt;&gt; Operator &gt;&gt; zahl2;

	switch(Operator)
	{
	case '*':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1*zahl2 &lt;&lt; endl;
		break;
	case '+':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1+zahl2 &lt;&lt; endl;
		break;
	case '-':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1-zahl2 &lt;&lt; endl;
		break;
	case '/':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1/zahl2 &lt;&lt; endl;
		break;	
	}
	marke:;
	cout &lt;&lt; &quot;Nochmal? (j/n)&quot;;
	cin &gt;&gt; Nochmal;
	if(Nochmal == 'j' || Nochmal == 'J')
		;
	else if(Nochmal == 'n' || Nochmal == 'N')
	{
		return EXIT_SUCCESS;
	}
	else
	{
		cout &lt;&lt; &quot;Falsche Eingabe&quot; &lt;&lt; endl;
		goto marke;
	}
	}while(1);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/264258/welche-der-beiden-möglichkeiten-ist-quot-saubererer-quot-code</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 04:00:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/264258.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 05 Apr 2010 10:49:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Welche der beiden Möglichkeiten ist &amp;quot;saubererer&amp;quot; Code? on Mon, 05 Apr 2010 10:49:09 GMT]]></title><description><![CDATA[<p>Hallo. Ich wollte Euch fragen, was der &quot;bessere&quot; Code von beiden ist:</p>
<p>1. mit einer <code>for</code> -Schleife:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

int main()
{
	char Nochmal = 'n';
	do
	{
	system(&quot;cls&quot;);
	cout &lt;&lt; &quot;Taschenrechner:\nGeben Sie eine Zahl, den Operanden und die andere Zahl ein:\n&quot;;

	double zahl1 = 0.0, zahl2 = 0.0;
	char Operator;

	cin &gt;&gt; zahl1 &gt;&gt; Operator &gt;&gt; zahl2;

	switch(Operator)
	{
	case '*':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1*zahl2 &lt;&lt; endl;
		break;
	case '+':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1+zahl2 &lt;&lt; endl;
		break;
	case '-':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1-zahl2 &lt;&lt; endl;
		break;
	case '/':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1/zahl2 &lt;&lt; endl;
		break;	
	}
	for(;;)
	{
		cout &lt;&lt; &quot;Nochmal? (j/n)&quot;;
		cin &gt;&gt; Nochmal;

		if(Nochmal == 'j' || Nochmal == 'J')
			break;
		else if(Nochmal == 'n' || Nochmal == 'N')
		{
			return EXIT_SUCCESS;
		}
		else
		{
			cout &lt;&lt; &quot;Falsche Eingabe&quot; &lt;&lt; endl;
		}
	}
	}while(1);
}
</code></pre>
<p>2. mit <code>goto</code> :</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

int main()
{
	char Nochmal = 'n';
	do
	{
	system(&quot;cls&quot;);
	cout &lt;&lt; &quot;Taschenrechner:\nGeben Sie eine Zahl, den Operanden und die andere Zahl ein:\n&quot;;

	double zahl1 = 0.0, zahl2 = 0.0;
	char Operator;

	cin &gt;&gt; zahl1 &gt;&gt; Operator &gt;&gt; zahl2;

	switch(Operator)
	{
	case '*':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1*zahl2 &lt;&lt; endl;
		break;
	case '+':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1+zahl2 &lt;&lt; endl;
		break;
	case '-':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1-zahl2 &lt;&lt; endl;
		break;
	case '/':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1/zahl2 &lt;&lt; endl;
		break;	
	}
	marke:;
	cout &lt;&lt; &quot;Nochmal? (j/n)&quot;;
	cin &gt;&gt; Nochmal;
	if(Nochmal == 'j' || Nochmal == 'J')
		;
	else if(Nochmal == 'n' || Nochmal == 'N')
	{
		return EXIT_SUCCESS;
	}
	else
	{
		cout &lt;&lt; &quot;Falsche Eingabe&quot; &lt;&lt; endl;
		goto marke;
	}
	}while(1);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1877766</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1877766</guid><dc:creator><![CDATA[skullyan]]></dc:creator><pubDate>Mon, 05 Apr 2010 10:49:09 GMT</pubDate></item><item><title><![CDATA[Reply to Welche der beiden Möglichkeiten ist &amp;quot;saubererer&amp;quot; Code? on Mon, 05 Apr 2010 15:01:40 GMT]]></title><description><![CDATA[<p>Ach Mist, falsches Forum...<br />
Vergebt mir...<br />
<img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1877768</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1877768</guid><dc:creator><![CDATA[skullyan]]></dc:creator><pubDate>Mon, 05 Apr 2010 15:01:40 GMT</pubDate></item><item><title><![CDATA[Reply to Welche der beiden Möglichkeiten ist &amp;quot;saubererer&amp;quot; Code? on Mon, 05 Apr 2010 10:55:26 GMT]]></title><description><![CDATA[<p>Weder noch. Sauber wäre eine bool'sche Variable (int in C, bool in C++) die angibt ob weitergemacht werden soll. Diese ist Bestandteil des Schleifen-Ausdrucks.</p>
<p>Weder ein return aus der Mitte der Funktion, noch ein goto sind sauberer Code.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1877769</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1877769</guid><dc:creator><![CDATA[Janjan]]></dc:creator><pubDate>Mon, 05 Apr 2010 10:55:26 GMT</pubDate></item><item><title><![CDATA[Reply to Welche der beiden Möglichkeiten ist &amp;quot;saubererer&amp;quot; Code? on Mon, 05 Apr 2010 11:02:17 GMT]]></title><description><![CDATA[<p>Janjan schrieb:</p>
<blockquote>
<p>Weder noch.</p>
</blockquote>
<p>Sehe ich auch so.</p>
<p>Janjan schrieb:</p>
<blockquote>
<p>Sauber wäre eine bool'sche Variable</p>
</blockquote>
<p>Sehe ich nicht so.</p>
<p>return ist sehr stark und die dahingehende bewußte Abkehr von der Strukturierten Programmierung ist fast immer ein Gewinn.</p>
<p>Hier würde ich eventuell die Frage inclusive Idiotenschleife auslagern und die gesuchte bool-Variable für die Hauptschleife würde der Rückgabewert sein. Könnte sich hübsch anfühlen, aber genau weiß man das immer erst, wenn man es ausprogrammiert hat, fürchte ich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1877772</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1877772</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 05 Apr 2010 11:02:17 GMT</pubDate></item><item><title><![CDATA[Reply to Welche der beiden Möglichkeiten ist &amp;quot;saubererer&amp;quot; Code? on Mon, 05 Apr 2010 11:06:27 GMT]]></title><description><![CDATA[<p>Janjan schrieb:</p>
<blockquote>
<p>Weder noch. Sauber wäre eine bool'sche Variable (int in C, bool in C++) die angibt ob weitergemacht werden soll. Diese ist Bestandteil des Schleifen-Ausdrucks.</p>
<p>Weder ein return aus der Mitte der Funktion, noch ein goto sind sauberer Code.</p>
</blockquote>
<p>Praktisch so?</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

int main()
{
	char Nochmal = 'n';
	bool schalt = false;
	do
	{
	system(&quot;cls&quot;);
	cout &lt;&lt; &quot;Taschenrechner:\nGeben Sie eine Zahl, den Operanden und die andere Zahl ein:\n&quot;;

	double zahl1 = 0.0, zahl2 = 0.0;
	char Operator;

	cin &gt;&gt; zahl1 &gt;&gt; Operator &gt;&gt; zahl2;

	switch(Operator)
	{
	case '*':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1*zahl2 &lt;&lt; endl;
		break;
	case '+':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1+zahl2 &lt;&lt; endl;
		break;
	case '-':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1-zahl2 &lt;&lt; endl;
		break;
	case '/':
		cout &lt;&lt; &quot;Ergibt: &quot; &lt;&lt; zahl1/zahl2 &lt;&lt; endl;	
	}
	cout &lt;&lt; &quot;Nochmal? (1 = j/0 = n)&quot;;
	cin &gt;&gt; schalt;
	}while(schalt);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1877774</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1877774</guid><dc:creator><![CDATA[skullyan]]></dc:creator><pubDate>Mon, 05 Apr 2010 11:06:27 GMT</pubDate></item><item><title><![CDATA[Reply to Welche der beiden Möglichkeiten ist &amp;quot;saubererer&amp;quot; Code? on Mon, 05 Apr 2010 11:23:06 GMT]]></title><description><![CDATA[<p>Immerhin hast du 10 Zeilen eingespart ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1877782</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1877782</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Mon, 05 Apr 2010 11:23:06 GMT</pubDate></item><item><title><![CDATA[Reply to Welche der beiden Möglichkeiten ist &amp;quot;saubererer&amp;quot; Code? on Mon, 05 Apr 2010 13:49:47 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile-var-mode-is-viewprofile-and-u-is-100590.html" rel="nofollow">Martin Richter</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-4.html" rel="nofollow">WinAPI</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-15.html" rel="nofollow">C++</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39405.html" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1877829</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1877829</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Mon, 05 Apr 2010 13:49:47 GMT</pubDate></item><item><title><![CDATA[Reply to Welche der beiden Möglichkeiten ist &amp;quot;saubererer&amp;quot; Code? on Mon, 05 Apr 2010 13:51:47 GMT]]></title><description><![CDATA[<p>Versuche die Ein-/Ausgabe von der Funktionalität zu trennen, am besten schiebst du die Funktionalität in eine Funktion, dann lässt sich das sicher übersichtlicher schreiben.</p>
<p>MfG SideWinder</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1877831</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1877831</guid><dc:creator><![CDATA[SideWinder]]></dc:creator><pubDate>Mon, 05 Apr 2010 13:51:47 GMT</pubDate></item><item><title><![CDATA[Reply to Welche der beiden Möglichkeiten ist &amp;quot;saubererer&amp;quot; Code? on Mon, 05 Apr 2010 13:56:48 GMT]]></title><description><![CDATA[<p>skullyan schrieb:</p>
<blockquote>
<pre><code class="language-cpp">system(&quot;cls&quot;);
</code></pre>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1877835</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1877835</guid><dc:creator><![CDATA[lagalopex]]></dc:creator><pubDate>Mon, 05 Apr 2010 13:56:48 GMT</pubDate></item></channel></rss>