<?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[Scope der While-Schleife]]></title><description><![CDATA[<p>Hi,</p>
<p>wird der Scope der While-Schleife verlassen, wenn die Bedingung geprüft wird? Den Ausgaben zufole eigentlich nicht. Dies könnte aber auch an Optimierungsgründen liegen.</p>
<pre><code class="language-cpp">int i = 0 ;

while(i++ &lt; 2)
{
	cout &lt;&lt; &quot;vor Initialisierung: &quot; &lt;&lt; endl ;

	int a ; // Deklaration
	cout &lt;&lt; &quot;vor Initialisierung: &quot; &lt;&lt; endl ;
	cout &lt;&lt;	&quot;a = &quot; &lt;&lt; a &lt;&lt; &quot; address = &quot; &lt;&lt; &amp;a &lt;&lt; endl &lt;&lt; endl ;

	a = 6 ; // (Re-)Initialisierung

	cout &lt;&lt; &quot;nach Initialiserung: &quot; &lt;&lt; endl ;
	cout &lt;&lt;	&quot;a = &quot; &lt;&lt; a &lt;&lt; &quot; address = &quot; &lt;&lt; &amp;a &lt;&lt; endl &lt;&lt; endl ;
}
</code></pre>
<pre><code>/*
vor Initialisierung:
a = -858993460 address = 001FFA84

nach Initialiserung:
a = 6 address = 001FFA84

vor Initialisierung:
a = 6 address = 001FFA84

nach Initialiserung:
a = 6 address = 001FFA84
*/
</code></pre>
<p>MfG,<br />
WilMen</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/235286/scope-der-while-schleife</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 06:16:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/235286.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 27 Feb 2009 22:02:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Scope der While-Schleife on Fri, 27 Feb 2009 22:02:50 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>wird der Scope der While-Schleife verlassen, wenn die Bedingung geprüft wird? Den Ausgaben zufole eigentlich nicht. Dies könnte aber auch an Optimierungsgründen liegen.</p>
<pre><code class="language-cpp">int i = 0 ;

while(i++ &lt; 2)
{
	cout &lt;&lt; &quot;vor Initialisierung: &quot; &lt;&lt; endl ;

	int a ; // Deklaration
	cout &lt;&lt; &quot;vor Initialisierung: &quot; &lt;&lt; endl ;
	cout &lt;&lt;	&quot;a = &quot; &lt;&lt; a &lt;&lt; &quot; address = &quot; &lt;&lt; &amp;a &lt;&lt; endl &lt;&lt; endl ;

	a = 6 ; // (Re-)Initialisierung

	cout &lt;&lt; &quot;nach Initialiserung: &quot; &lt;&lt; endl ;
	cout &lt;&lt;	&quot;a = &quot; &lt;&lt; a &lt;&lt; &quot; address = &quot; &lt;&lt; &amp;a &lt;&lt; endl &lt;&lt; endl ;
}
</code></pre>
<pre><code>/*
vor Initialisierung:
a = -858993460 address = 001FFA84

nach Initialiserung:
a = 6 address = 001FFA84

vor Initialisierung:
a = 6 address = 001FFA84

nach Initialiserung:
a = 6 address = 001FFA84
*/
</code></pre>
<p>MfG,<br />
WilMen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1671675</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1671675</guid><dc:creator><![CDATA[WilMen]]></dc:creator><pubDate>Fri, 27 Feb 2009 22:02:50 GMT</pubDate></item><item><title><![CDATA[Reply to Scope der While-Schleife on Fri, 27 Feb 2009 22:10:14 GMT]]></title><description><![CDATA[<p>Ja, der Gültigkeitsbereich endet wie bei jedem Block bei der schliessenden geschweiften Klammer. Da du auf dem Stack arbeitest, wird das oberste Element <code>a</code> gepopt und im neuen Durchgang wieder gepusht, deshalb hat es die gleiche Adresse.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1671679</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1671679</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Fri, 27 Feb 2009 22:10:14 GMT</pubDate></item><item><title><![CDATA[Reply to Scope der While-Schleife on Sat, 28 Feb 2009 10:36:26 GMT]]></title><description><![CDATA[<p>Hi Nexus!</p>
<p>Wenn ich dem Visual C++ Debugger Glauben schenke, dann bleibt &quot;a&quot; deklariert. Nicht deklarierte Variablen werden transparent angezeigt, &quot;a2 wird aber die ganze Zeit über wie eine globale Variable angezeigt, wenn ich es &quot;überwache&quot;. Fasst der Debugger &quot;a&quot; als durchgehend deklariert auf, weil es immer die gleiche Adresse bekommt?</p>
<p>MfG<br />
WilMen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1671824</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1671824</guid><dc:creator><![CDATA[WilMen]]></dc:creator><pubDate>Sat, 28 Feb 2009 10:36:26 GMT</pubDate></item><item><title><![CDATA[Reply to Scope der While-Schleife on Sat, 28 Feb 2009 11:00:09 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/14524">@WilMen</a>,<br />
Laut Standard sieht der Scope der while Schleife so aus:<br />
&quot;6.5.1 The while statement&quot; Abschnitt 2</p>
<pre><code class="language-cpp">label:
{ // Start of while scope

  /* was auch immer im Kopf steht */

  if(/* Resultat im Kopf */)
  {
    // Inhalt der While-Schleife.
    goto label;
  }

} // End of while scope
</code></pre>
<p>Du kannst sowas sehr einfach auch selber prüfen:</p>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;iostream&gt;

class ScopeLog
{
private:
  std::string m_name;

public:
  ScopeLog(std::string const&amp; name)
    : m_name(name)
  {
    std::cout &lt;&lt; &quot;C-Tor: &quot; &lt;&lt; m_name &lt;&lt; std::endl;
  }

  ~ScopeLog()
  {
    std::cout &lt;&lt; &quot;D-Tor:&quot; &lt;&lt; m_name &lt;&lt; std::endl;
  }
};

int main()
{
  int i = 0;
  while(i &lt; 5)
  {
    ScopeLog log(&quot;In While&quot;);
    ++i;
  }

  return 0;
}
</code></pre>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1671831</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1671831</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Sat, 28 Feb 2009 11:00:09 GMT</pubDate></item><item><title><![CDATA[Reply to Scope der While-Schleife on Sat, 28 Feb 2009 11:51:36 GMT]]></title><description><![CDATA[<p>Danke Dravere!</p>
<p>Sehr gutes Beispiel, jetzt bin ich überzeugt!</p>
<p>MfG WilMen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1671864</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1671864</guid><dc:creator><![CDATA[WilMen]]></dc:creator><pubDate>Sat, 28 Feb 2009 11:51:36 GMT</pubDate></item><item><title><![CDATA[Reply to Scope der While-Schleife on Sat, 28 Feb 2009 11:59:03 GMT]]></title><description><![CDATA[<p>Nur noch zum anmerken. Du kannst Scopes auch ganz von irgendwelchen anderen Konstrukten abgelöst haben..</p>
<p>Um mich mal an Draveres Beispiel zu hängen:</p>
<pre><code class="language-cpp">int main()
{
  int i = 0;

  { 
    ScopeLog log(&quot;Einfach ein Scope&quot;);
    ++i;
  } // log wird zerstört

  return 0;
}
</code></pre>
<p>wirkt komisch, findet allerdings durchaus Verwendung</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1671870</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1671870</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sat, 28 Feb 2009 11:59:03 GMT</pubDate></item><item><title><![CDATA[Reply to Scope der While-Schleife on Sat, 28 Feb 2009 21:13:54 GMT]]></title><description><![CDATA[<p>Hi drakon!</p>
<p>Danke, aber das wusste ich! Ich fand es nur komisch, dass der Scope beim Abfragen der Bedingung verlassen wird, weil Schleifenkopf, solange nicht mit &quot;;&quot; abgeschlossen, und Schleifenkörper ja quasi eine Einheit bilden.</p>
<pre><code class="language-cpp">// eine &quot;Einheit&quot;
while(/* ... */) 
{
 \\ ... 
}

// keine &quot;Einheit&quot;
while (/* ... */) ;

{
 \\ ...
}
</code></pre>
<p>MfG<br />
WilMen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1672171</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1672171</guid><dc:creator><![CDATA[WilMen]]></dc:creator><pubDate>Sat, 28 Feb 2009 21:13:54 GMT</pubDate></item></channel></rss>