<?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[switch vs. else if]]></title><description><![CDATA[<p>Kann mir mal jemand den unterschied erklären (falls es einen gibt) und mir sagen, warum es switch anweisungen in c++ gibt?</p>
<p>Ich meine das hier:</p>
<pre><code>Event e = getEvent();
switch(e){
case MouseEvent:
break;
case KeyboardEvent:
break;
default:
break;
}
</code></pre>
<p>ist doch genau das gleiche wie das:</p>
<pre><code>Event e = getEvent();
if(e == MouseEvent){}
else if(e == KeyboardEvent){}
else{}
</code></pre>
<p>demnach sind switch anweisungen doch eigentlich überflüssig oder nicht?<br />
Gehe mal nicht davon aus, dass die wirklich unnötig sind, aber ich sehe von meinem blickwinkel keinen unterschied.</p>
<p>und besser zu lesen ist es auch mit if-anweisungen anstatt dem case: default: break; zeug</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/314298/switch-vs-else-if</link><generator>RSS for Node</generator><lastBuildDate>Sat, 01 Aug 2026 08:55:25 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/314298.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 26 Feb 2013 19:59:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 20:00:34 GMT]]></title><description><![CDATA[<p>Kann mir mal jemand den unterschied erklären (falls es einen gibt) und mir sagen, warum es switch anweisungen in c++ gibt?</p>
<p>Ich meine das hier:</p>
<pre><code>Event e = getEvent();
switch(e){
case MouseEvent:
break;
case KeyboardEvent:
break;
default:
break;
}
</code></pre>
<p>ist doch genau das gleiche wie das:</p>
<pre><code>Event e = getEvent();
if(e == MouseEvent){}
else if(e == KeyboardEvent){}
else{}
</code></pre>
<p>demnach sind switch anweisungen doch eigentlich überflüssig oder nicht?<br />
Gehe mal nicht davon aus, dass die wirklich unnötig sind, aber ich sehe von meinem blickwinkel keinen unterschied.</p>
<p>und besser zu lesen ist es auch mit if-anweisungen anstatt dem case: default: break; zeug</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302294</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302294</guid><dc:creator><![CDATA[gamer8o4]]></dc:creator><pubDate>Tue, 26 Feb 2013 20:00:34 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 20:04:36 GMT]]></title><description><![CDATA[<p>Schreibarbeit.<br />
Du sparst dir das ewige foo ==.<br />
Obs schneller ist weiß ich nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302296</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302296</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Tue, 26 Feb 2013 20:04:36 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 20:05:15 GMT]]></title><description><![CDATA[<p>gamer8o4 schrieb:</p>
<blockquote>
<p>und besser zu lesen ist es auch mit if-anweisungen anstatt dem case: default: break; zeug</p>
</blockquote>
<p>Auch nur wenn man so wie du formatiert.</p>
<p><code>switch</code> ist eine Fallunterscheidung für Integer-Konstanten und kann übersichtlicher und um einiges schneller sein als eine entsprechende <code>if</code> - <code>else</code> -Kaskade.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302297</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302297</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 26 Feb 2013 20:05:15 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 20:05:34 GMT]]></title><description><![CDATA[<p>gamer8o4 schrieb:</p>
<blockquote>
<p>ist doch genau das gleiche</p>
</blockquote>
<p>Ohne die <code>break</code> nicht mehr...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302298</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302298</guid><dc:creator><![CDATA[Caligulaminus]]></dc:creator><pubDate>Tue, 26 Feb 2013 20:05:34 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 20:14:50 GMT]]></title><description><![CDATA[<p>gamer8o4 schrieb:</p>
<blockquote>
<p>demnach sind switch anweisungen doch eigentlich überflüssig oder nicht?</p>
</blockquote>
<p>Demnach sind <code>For</code> -Schleifen doch eigentlich überflüssig oder nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302303</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302303</guid><dc:creator><![CDATA[while vs for]]></dc:creator><pubDate>Tue, 26 Feb 2013 20:14:50 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 20:17:47 GMT]]></title><description><![CDATA[<p>Nee, while.<br />
Ich schreibe lieber for(; bar; ) als std::size_t i = 0; while (i &lt; bar) {foo(); ++i;}</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302304</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302304</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Tue, 26 Feb 2013 20:17:47 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 20:27:50 GMT]]></title><description><![CDATA[<blockquote>
<p>switch ist eine Fallunterscheidung für Integer-Konstanten und kann übersichtlicher und um einiges schneller sein als eine entsprechende if-else-Kaskade.</p>
</blockquote>
<p>okay, also bei integer-konstanten lieber switch benutzen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302311</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302311</guid><dc:creator><![CDATA[gamer8o4]]></dc:creator><pubDate>Tue, 26 Feb 2013 20:27:50 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 20:29:22 GMT]]></title><description><![CDATA[<p>Nathan schrieb:</p>
<blockquote>
<p>Nee, while.<br />
Ich schreibe lieber for(; bar; ) als std::size_t i = 0; while (i &lt; bar) {foo(); ++i;}</p>
</blockquote>
<p>Das war doch offensichtlich nicht ernst gemeint.</p>
<p>@TE: Siehe Antwort von Nexus, der Thread kann geschlossen werden <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302312</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302312</guid><dc:creator><![CDATA[mapper]]></dc:creator><pubDate>Tue, 26 Feb 2013 20:29:22 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 20:50:50 GMT]]></title><description><![CDATA[<p>Meins auch nicht.<br />
Wenn, dann würde ich lieber auf while verzichten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302324</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302324</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Tue, 26 Feb 2013 20:50:50 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 21:17:40 GMT]]></title><description><![CDATA[<p>Ich vermute mal, dass ein Switch fuer den Compiler leichter optimierbar ist (Sprungtabelle).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302335</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302335</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Tue, 26 Feb 2013 21:17:40 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 21:22:28 GMT]]></title><description><![CDATA[<p>switch-case kann man auch einfacher debuggen. Dann springt der Compiler gleich an die richtige Stelle, bei if-else musst du alle Überprüfungen durchsteppen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302336</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302336</guid><dc:creator><![CDATA[Mechanics]]></dc:creator><pubDate>Tue, 26 Feb 2013 21:22:28 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 21:52:43 GMT]]></title><description><![CDATA[<p>Mechanics schrieb:</p>
<blockquote>
<p>switch-case kann man auch einfacher debuggen. Dann springt der Compiler gleich an die richtige Stelle, bei if-else musst du alle Überprüfungen durchsteppen.</p>
</blockquote>
<p>okay, also compileroptimierungen und einfacher zu debuggen. also wenn möglich bevorzugen?!</p>
<p>Wer von euch nimmt denn öfter switch und wer if?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302346</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302346</guid><dc:creator><![CDATA[gamer8o4]]></dc:creator><pubDate>Tue, 26 Feb 2013 21:52:43 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 21:54:57 GMT]]></title><description><![CDATA[<p>Ich nehm switch, wenn es geht (Typ) und es mehr als zwei Verzweigungen gibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302347</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302347</guid><dc:creator><![CDATA[Eisflamme]]></dc:creator><pubDate>Tue, 26 Feb 2013 21:54:57 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 21:57:42 GMT]]></title><description><![CDATA[<p>gamer8o4 schrieb:</p>
<blockquote>
<p>Wer von euch nimmt denn öfter switch und wer if?</p>
</blockquote>
<p>Natürlich nimmt man viel öfter if. switch-case geht ja nur in bestimmten Situationen. Aber wenn du schon sowas wie ein enum oder was ähnliches hast, wo du mehrere Werte abfragen willst, dann bietet sich switch-case eher an.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302350</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302350</guid><dc:creator><![CDATA[Mechanics]]></dc:creator><pubDate>Tue, 26 Feb 2013 21:57:42 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 22:03:33 GMT]]></title><description><![CDATA[<p>Mechanics schrieb:</p>
<blockquote>
<p>switch-case kann man auch einfacher debuggen. Dann springt der Compiler gleich an die richtige Stelle, bei if-else musst du alle Überprüfungen durchsteppen.</p>
</blockquote>
<p>Was nun aber wirklich kein Grund ist, weshalb <code>switch</code> existiert. C (und C++ schon gar nicht) wurde nicht designt um einfach zu Debuggen zu sein und um schöne Fehlermeldungen zu erhalten.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/28561">@gamer8o4</a>: Es gibt so eine These, dass alle if/else durch Polymorphie ersetzt werden können. Ich habe bei mir nur etwa alle 100 Zeilen ein if (10k Zeilen Statistikgrundlage). Muss auch nicht zwingend Runtimepolymorphie sein, Templates tuns auch. switch habe ich eines bei <code>getopt</code> aber das wars dann auch schon.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302352</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302352</guid><dc:creator><![CDATA[bagger]]></dc:creator><pubDate>Tue, 26 Feb 2013 22:03:33 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 22:05:32 GMT]]></title><description><![CDATA[<p>rofl, den Code will ich sehen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302353</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302353</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Tue, 26 Feb 2013 22:05:32 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 22:09:03 GMT]]></title><description><![CDATA[<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/28561">@gamer8o4</a>: Es gibt so eine These, dass alle if/else durch Polymorphie ersetzt werden können. Ich habe bei mir nur etwa alle 100 Zeilen ein if (10k Zeilen Statistikgrundlage). Muss auch nicht zwingend Runtimepolymorphie sein, Templates tuns auch. switch habe ich eines bei getopt aber das wars dann auch schon.</p>
</blockquote>
<p>echt? nur alle 100 zeilen eins? ich glaub ich sollte meinen programmierstil überarbeiten, aber ich wüsste garnicht viele stellen wo ich auf die if anweisungen verzichten könnte <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":/"
      alt="😕"
    /> das man das mit templates lösen kann ist bei mir doch eher die ausnahme</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302354</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302354</guid><dc:creator><![CDATA[gamer8o4]]></dc:creator><pubDate>Tue, 26 Feb 2013 22:09:03 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 22:13:06 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>rofl, den Code will ich sehen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
</blockquote>
<p>Der Code ist ein voll funktionsfähiger Interpreter einer Programmiersprache.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/28561">@gamer8o4</a>: Zeig mal ein paar deiner ifs, dann kann ich mal schauen (und ohne externes C-Zeugs wie dein getEvent(), da hat man wirklich keine Wahl).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302355</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302355</guid><dc:creator><![CDATA[bagger]]></dc:creator><pubDate>Tue, 26 Feb 2013 22:13:06 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 22:15:18 GMT]]></title><description><![CDATA[<p>gamer8o4 schrieb:</p>
<blockquote>
<p>echt? nur alle 100 zeilen eins? ich glaub ich sollte meinen programmierstil überarbeiten</p>
</blockquote>
<p>Du solltest nicht sofort auf alles hören, was dir jemand sagt. Allerdings stimmt es schon, dass man viele if Abfragen tatsächlich umgehen und eleganter lösen kann, eben auch durch Polymorphie oder Templates. Aber bitte nicht alle und schon gar nicht aus Prinzip, sondern nur wenns Sinn macht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302357</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302357</guid><dc:creator><![CDATA[Mechanics]]></dc:creator><pubDate>Tue, 26 Feb 2013 22:15:18 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 22:40:48 GMT]]></title><description><![CDATA[<p>Warst du nicht ein Fan von Alexandrescu? Von dem wirst du eine Linked List ohne if-Abfragen finden.</p>
<p>Btw: Natürlich habe ich ein paar ifs. Eben alle 100 Zeilen. Was ich nicht habe, sind immer wieder ähnliche ifs, die sich wiederholen. Eine verlinkte Liste würde ich zum Beispiel auch mit einem if schreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302363</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302363</guid><dc:creator><![CDATA[bagger]]></dc:creator><pubDate>Tue, 26 Feb 2013 22:40:48 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Tue, 26 Feb 2013 22:49:00 GMT]]></title><description><![CDATA[<p>bagger schrieb:</p>
<blockquote>
<p>Ich habe bei mir nur etwa alle 100 Zeilen ein if</p>
</blockquote>
<p>Hm, muss ein recht primitives Programm sein. Oder ein Programmierstil, der viele Zeilen benötigt. Ich komme bei meiner Matrix-Klasse auf etwa 8 if's in 100 Zeilen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302365</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302365</guid><dc:creator><![CDATA[Ramanujan]]></dc:creator><pubDate>Tue, 26 Feb 2013 22:49:00 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Wed, 27 Feb 2013 01:50:33 GMT]]></title><description><![CDATA[<p>bagger schrieb:</p>
<blockquote>
<p>Warst du nicht ein Fan von Alexandrescu? Von dem wirst du eine Linked List ohne if-Abfragen finden.</p>
<p>Btw: Natürlich habe ich ein paar ifs. Eben alle 100 Zeilen. Was ich nicht habe, sind immer wieder ähnliche ifs, die sich wiederholen. Eine verlinkte Liste würde ich zum Beispiel auch mit einem if schreiben.</p>
</blockquote>
<p>Einen Stack als einfach verlinkte Liste würde ich ohne if schreiben. (Und natürlich ohne if-Plagiate als Polymorphie, ?:-Operator oder Schleifen, die maximal einmal laufen.)</p>
<p>Einen Stack oder eine Queue als doppelt verkettete Liste würde ich ohne if schreiben.</p>
<p>Eine Queue als einfach verlinkte Liste,... müßte ich mal machen, aber die Zeichen stehen eigentlich nicht so stark nach if.</p>
<p>if kostet Laufzeit und macht den Code unwartbar, weil man mehrere Zweige beachten muss. if ist böse. Es ist zu meiden. Aber nicht um jeden Preis.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302388</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302388</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Wed, 27 Feb 2013 01:50:33 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Wed, 27 Feb 2013 01:47:32 GMT]]></title><description><![CDATA[<p>bagger schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/28561">@gamer8o4</a>: Es gibt so eine These, dass alle if/else durch Polymorphie ersetzt werden können.</p>
</blockquote>
<p>Oh, ich dachte fast, ich wäre allein bei so extremen Thesen.</p>
<p>Diese hier habe ich afair ungefähr Neujahr 2002 ausgetestet. Ein Programm, das Homepages uploaden kann per ftp, dazu liegen lokal ein Ausgabeverzeichnis und ein Spiegelverzeichnis (das immer gleich wie das aus dem Server ist) und das Programm synchronisiert Ausgabe- und Spiegenverzeichnis und updatet dabei das Serververzeichnis.</p>
<p>Das alles noch multithreaded mit mehreren ftp-Verbindungen. Gar nicht so einfach, weil bei vorhandener Datei /foo ein put /foo/bar erst nach rm /foo mkdir foo geht und dazu das rm /foo erst nach rm /foo/bar geht. Und die rm und mkdir sollten voll verschränkt sein, auch mit allen anderen put. So, daß die Gesamt-Onlinezeit minimal ist. Für Wählverbindungen. Daß keine Verbindung erstellt wird, wenn keine Updates zu erfolgen haben, ist wohl klar, damit man es auch regelmäßig Scriptgesteuert nutzen kann. Und auch kein schlichtes Probieren-und-Verwerfen, sondern ich legte erst singlethreaded einen Plan als Netzwerk mit Vor- und Nachbedingungen an und arbeitet den dann multithreaded ab.</p>
<p>Und das alles ohne if! Außer da, wo es aus der API erzwungen ist, beim Parsen der WIN32_FIND_DATA-Struktur. Die wird aber dann sofort je nachdem, ob Datei oder Verzeichnis in die passend Klasse gestopft, damit ab dann die Polymorphie greift.</p>
<p>Dabei nicht geschummelt mit statt if(a)b ein while(a);{b;break;}.</p>
<p>Das hat zwar geklappt, und der Code war in seiner eigenen Weise sogar wunderwunderschön. Aber wartbar war er nicht mehr. Hübscher Test, der mich sehr gut einjustiert hat, wo if und wo Polymorphie angemessener ist.</p>
<p>Siehe hier auch den Thread über MI oder nicht MI. Da testet einer, um man fast immer vererben kann, statt Attribute zu nehmen, leider testet er nicht, sondern tut es einfach, sogar in Produktiv-Code. Aua, wird der auf die Schnauze fallen.</p>
<p>bagger schrieb:</p>
<blockquote>
<p>Ich habe bei mir nur etwa alle 100 Zeilen ein if (10k Zeilen Statistikgrundlage). Muss auch nicht zwingend Runtimepolymorphie sein, Templates tuns auch.</p>
</blockquote>
<p>Das erscheint mir ein Bißchen zu wenig zu sein.</p>
<p>bagger schrieb:</p>
<blockquote>
<p>switch habe ich eines bei <code>getopt</code> aber das wars dann auch schon.</p>
</blockquote>
<p>Jo, switch ist quasi ausgestorben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302391</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302391</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Wed, 27 Feb 2013 01:47:32 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Wed, 27 Feb 2013 05:03:12 GMT]]></title><description><![CDATA[<p>bagger schrieb:</p>
<blockquote>
<p>Es gibt so eine These, dass alle if/else durch Polymorphie ersetzt werden können.</p>
</blockquote>
<p>Wieder mal ein gutes Beispiel, dass Code erst gut wird, wenn er kompliziert ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302399</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302399</guid><dc:creator><![CDATA[tadada]]></dc:creator><pubDate>Wed, 27 Feb 2013 05:03:12 GMT</pubDate></item><item><title><![CDATA[Reply to switch vs. else if on Wed, 27 Feb 2013 07:51:04 GMT]]></title><description><![CDATA[<p>Das Problem an switch (aber auch der Vorteil) ist doch seine Statik.</p>
<p>Das hier geht nur mit einem if und nie mit einem switch:</p>
<pre><code>int i;
int j;
cin &gt;&gt; i &gt;&gt; j;

switch (i)
case j:
    cout &lt;&lt; &quot;Gleich&quot; &lt;&lt; endl;
    break;
</code></pre>
<p>Weil zur Compiletime muss der Ausdruck am case konstant sein. Dadurch ist das für dem Compiler halt leichter zu optimieren (statische Sprungtabelle).<br />
Aber es ist halt nicht zur Laufzeit dynamisch als, dass man 2 Userinput vergleichen kann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302422</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302422</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Wed, 27 Feb 2013 07:51:04 GMT</pubDate></item></channel></rss>