<?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[Wie kann man zählen wie oft eine schleife durchläuft?]]></title><description><![CDATA[<p>Morgen,</p>
<p>also meine Frage ist wie ich in Schleifen zählen kann wie oft sie durchgelaufen ist ich weis das es da was gab aber ich weis nicht mehr was. Und dann noch wie man zählen kann wie hoch die anzahl der geschriebenen werte ist. Hier der Code ich markier die stelle und schreib nen Kommentar.</p>
<pre><code class="language-cpp">#include &lt;math.h&gt;
#include &lt;fstream&gt;
#include &lt;iostream&gt; 
#include &lt;string&gt;
#include&lt;vector&gt;
#define sqr(x) ((x)*(x))
#define sin_d(x) (sin((x)*M_PI/180))
#define cos_d(x) (cos((x)*M_PI/180))
#define tan_d(x) (tan((x)*M_PI/180))
#define asin_d(x) (asin(x)*180/M_PI)
#define acos_d(x) (acos(x)*180/M_PI)
#define atan_d(x) (atan(x)*180/M_PI)
using namespace std;

int main()
{
  int x;
  int y;
  double r = 1.0;

    std::ofstream myFile;
    myFile.open (&quot;c:/ErstellteKugel.vtk&quot;);
    myFile &lt;&lt; &quot;# vtk DataFile Version 2.0\n&quot; &lt;&lt; &quot;Kugel example\n&quot; &lt;&lt; &quot;ASCII\n&quot; &lt;&lt; &quot;DATASET POLYDATA\n&quot;;
    myFile &lt;&lt; &quot;POINTS 308 float\n&quot;;   

    myFile &lt;&lt; &quot;0.000000 &quot; &lt;&lt; &quot;0.000000 &quot; &lt;&lt; &quot;1.000000\n&quot;;
    for( int phi = 10; phi &lt; 180; phi += 10 )  // bei dieser schleife wie krieg ich raus das sie 308 mal durchläuft
    {
        for( int theta = 0; theta &lt; 360; theta += 20 )
        {
            double x = r * cos_d(theta) * sin_d(phi);
             myFile &lt;&lt; x &lt;&lt;&quot; &quot;;
            double y = r * sin_d(theta) * sin_d(phi);
             myFile &lt;&lt; y &lt;&lt; &quot; &quot;;
            double z = r * cos_d(phi);
             myFile &lt;&lt; z &lt;&lt; &quot;\n&quot;;
        }
    }
      myFile &lt;&lt; &quot;0.000000 &quot; &lt;&lt; &quot;0.000000 &quot; &lt;&lt; &quot;-1.000000\n&quot;; 
      myFile &lt;&lt; &quot;POLYGONS 612 2448\n&quot;;              

    for(x=1; x&lt;= 17; x++)
    {                   
            myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; 0 &lt;&lt; &quot; &quot; &lt;&lt; x &lt;&lt; &quot; &quot; &lt;&lt;  x + 1 &lt;&lt; &quot;\n&quot;;
    }
            myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; 0 &lt;&lt; &quot; &quot; &lt;&lt; 18 &lt;&lt; &quot; &quot; &lt;&lt; 1 &lt;&lt; &quot;\n&quot;;       

    for(x=1, y=19; x&lt;=17&amp;&amp;y&lt;=36; x++, y++)
    {
            myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; x &lt;&lt; &quot; &quot; &lt;&lt; y &lt;&lt; &quot; &quot; &lt;&lt; y + 1 &lt;&lt; std::endl &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; x &lt;&lt; &quot; &quot; &lt;&lt; x + 1 &lt;&lt; &quot; &quot; &lt;&lt; y + 1 &lt;&lt; std::endl; 
    }

            myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; 18 &lt;&lt; &quot; &quot; &lt;&lt; 1 &lt;&lt; &quot; &quot; &lt;&lt; 19 &lt;&lt; &quot;\n&quot;;
            myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; 18 &lt;&lt; &quot; &quot; &lt;&lt; 36 &lt;&lt; &quot; &quot; &lt;&lt; 19 &lt;&lt; &quot;\n&quot;; 

    for(x=19, y=36; x&lt;=288&amp;&amp;y&lt;=304; x++, y++)
    {
            myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; x &lt;&lt; &quot; &quot; &lt;&lt; y &lt;&lt; &quot; &quot; &lt;&lt; y + 1 &lt;&lt; std::endl &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; x &lt;&lt; &quot; &quot; &lt;&lt; x + 1 &lt;&lt; &quot; &quot; &lt;&lt; y + 1 &lt;&lt; std::endl;

    }

            myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; 288 &lt;&lt; &quot; &quot; &lt;&lt; 305 &lt;&lt; &quot; &quot; &lt;&lt; 306 &lt;&lt; &quot;\n&quot;;
            myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; 288 &lt;&lt; &quot; &quot; &lt;&lt; 289 &lt;&lt; &quot; &quot; &lt;&lt; 306 &lt;&lt; &quot;\n&quot;;

    for(x=290, y=291; x&lt;=305&amp;&amp;y&lt;=306; x++, y++)
    {
         myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; 307 &lt;&lt; &quot; &quot; &lt;&lt; x &lt;&lt; &quot; &quot; &lt;&lt; y &lt;&lt; &quot;\n&quot;;

    }

    myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; 307 &lt;&lt; &quot; &quot; &lt;&lt; 289 &lt;&lt; &quot; &quot; &lt;&lt; 290 &lt;&lt; &quot;\n&quot;;
    myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; 307 &lt;&lt; &quot; &quot; &lt;&lt; 306 &lt;&lt; &quot; &quot; &lt;&lt; 289;

}
</code></pre>
<p>Danke schonmal</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/191754/wie-kann-man-zählen-wie-oft-eine-schleife-durchläuft</link><generator>RSS for Node</generator><lastBuildDate>Sun, 27 Sep 2026 06:24:33 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/191754.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 06 Sep 2007 08:32:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 09:27:04 GMT]]></title><description><![CDATA[<p>Morgen,</p>
<p>also meine Frage ist wie ich in Schleifen zählen kann wie oft sie durchgelaufen ist ich weis das es da was gab aber ich weis nicht mehr was. Und dann noch wie man zählen kann wie hoch die anzahl der geschriebenen werte ist. Hier der Code ich markier die stelle und schreib nen Kommentar.</p>
<pre><code class="language-cpp">#include &lt;math.h&gt;
#include &lt;fstream&gt;
#include &lt;iostream&gt; 
#include &lt;string&gt;
#include&lt;vector&gt;
#define sqr(x) ((x)*(x))
#define sin_d(x) (sin((x)*M_PI/180))
#define cos_d(x) (cos((x)*M_PI/180))
#define tan_d(x) (tan((x)*M_PI/180))
#define asin_d(x) (asin(x)*180/M_PI)
#define acos_d(x) (acos(x)*180/M_PI)
#define atan_d(x) (atan(x)*180/M_PI)
using namespace std;

int main()
{
  int x;
  int y;
  double r = 1.0;

    std::ofstream myFile;
    myFile.open (&quot;c:/ErstellteKugel.vtk&quot;);
    myFile &lt;&lt; &quot;# vtk DataFile Version 2.0\n&quot; &lt;&lt; &quot;Kugel example\n&quot; &lt;&lt; &quot;ASCII\n&quot; &lt;&lt; &quot;DATASET POLYDATA\n&quot;;
    myFile &lt;&lt; &quot;POINTS 308 float\n&quot;;   

    myFile &lt;&lt; &quot;0.000000 &quot; &lt;&lt; &quot;0.000000 &quot; &lt;&lt; &quot;1.000000\n&quot;;
    for( int phi = 10; phi &lt; 180; phi += 10 )  // bei dieser schleife wie krieg ich raus das sie 308 mal durchläuft
    {
        for( int theta = 0; theta &lt; 360; theta += 20 )
        {
            double x = r * cos_d(theta) * sin_d(phi);
             myFile &lt;&lt; x &lt;&lt;&quot; &quot;;
            double y = r * sin_d(theta) * sin_d(phi);
             myFile &lt;&lt; y &lt;&lt; &quot; &quot;;
            double z = r * cos_d(phi);
             myFile &lt;&lt; z &lt;&lt; &quot;\n&quot;;
        }
    }
      myFile &lt;&lt; &quot;0.000000 &quot; &lt;&lt; &quot;0.000000 &quot; &lt;&lt; &quot;-1.000000\n&quot;; 
      myFile &lt;&lt; &quot;POLYGONS 612 2448\n&quot;;              

    for(x=1; x&lt;= 17; x++)
    {                   
            myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; 0 &lt;&lt; &quot; &quot; &lt;&lt; x &lt;&lt; &quot; &quot; &lt;&lt;  x + 1 &lt;&lt; &quot;\n&quot;;
    }
            myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; 0 &lt;&lt; &quot; &quot; &lt;&lt; 18 &lt;&lt; &quot; &quot; &lt;&lt; 1 &lt;&lt; &quot;\n&quot;;       

    for(x=1, y=19; x&lt;=17&amp;&amp;y&lt;=36; x++, y++)
    {
            myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; x &lt;&lt; &quot; &quot; &lt;&lt; y &lt;&lt; &quot; &quot; &lt;&lt; y + 1 &lt;&lt; std::endl &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; x &lt;&lt; &quot; &quot; &lt;&lt; x + 1 &lt;&lt; &quot; &quot; &lt;&lt; y + 1 &lt;&lt; std::endl; 
    }

            myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; 18 &lt;&lt; &quot; &quot; &lt;&lt; 1 &lt;&lt; &quot; &quot; &lt;&lt; 19 &lt;&lt; &quot;\n&quot;;
            myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; 18 &lt;&lt; &quot; &quot; &lt;&lt; 36 &lt;&lt; &quot; &quot; &lt;&lt; 19 &lt;&lt; &quot;\n&quot;; 

    for(x=19, y=36; x&lt;=288&amp;&amp;y&lt;=304; x++, y++)
    {
            myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; x &lt;&lt; &quot; &quot; &lt;&lt; y &lt;&lt; &quot; &quot; &lt;&lt; y + 1 &lt;&lt; std::endl &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; x &lt;&lt; &quot; &quot; &lt;&lt; x + 1 &lt;&lt; &quot; &quot; &lt;&lt; y + 1 &lt;&lt; std::endl;

    }

            myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; 288 &lt;&lt; &quot; &quot; &lt;&lt; 305 &lt;&lt; &quot; &quot; &lt;&lt; 306 &lt;&lt; &quot;\n&quot;;
            myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; 288 &lt;&lt; &quot; &quot; &lt;&lt; 289 &lt;&lt; &quot; &quot; &lt;&lt; 306 &lt;&lt; &quot;\n&quot;;

    for(x=290, y=291; x&lt;=305&amp;&amp;y&lt;=306; x++, y++)
    {
         myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; 307 &lt;&lt; &quot; &quot; &lt;&lt; x &lt;&lt; &quot; &quot; &lt;&lt; y &lt;&lt; &quot;\n&quot;;

    }

    myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; 307 &lt;&lt; &quot; &quot; &lt;&lt; 289 &lt;&lt; &quot; &quot; &lt;&lt; 290 &lt;&lt; &quot;\n&quot;;
    myFile &lt;&lt; 3 &lt;&lt; &quot; &quot; &lt;&lt; 307 &lt;&lt; &quot; &quot; &lt;&lt; 306 &lt;&lt; &quot; &quot; &lt;&lt; 289;

}
</code></pre>
<p>Danke schonmal</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1359970</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1359970</guid><dc:creator><![CDATA[GT]]></dc:creator><pubDate>Thu, 06 Sep 2007 09:27:04 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 08:36:39 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int counter =0;
for( int phi = 10; phi &lt; 180; phi += 10 )  // bei dieser schleife wie krieg ich raus das sie 308 mal durchläuft 
    { 
        for( int theta = 0; theta &lt; 360; theta += 20 ) 
        { 
            double x = r * cos_d(theta) * sin_d(phi); 
             myFile &lt;&lt; x &lt;&lt;&quot; &quot;; 
            double y = r * sin_d(theta) * sin_d(phi); 
             myFile &lt;&lt; y &lt;&lt; &quot; &quot;; 
            double z = r * cos_d(phi); 
             myFile &lt;&lt; z &lt;&lt; &quot;\n&quot;; 
        } 
counter++;
    } 

std::cout &lt;&lt; &quot;Schleifeiterationen: &quot; &lt;&lt; counter &lt;&lt; std:endl;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1359977</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1359977</guid><dc:creator><![CDATA[BorisDieKlinge]]></dc:creator><pubDate>Thu, 06 Sep 2007 08:36:39 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 08:37:00 GMT]]></title><description><![CDATA[<p>Wie wärs mit ausrechnen? Die Schleife läuft von 10 bis 179 in 10er-Schritten.</p>
<p>Wie war doch gleich die Frage?!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1359978</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1359978</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Thu, 06 Sep 2007 08:37:00 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 08:42:52 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">for( int phi = 10, size_t counter=0; phi &lt; 180; phi += 10, ++counter )
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1359987</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1359987</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Thu, 06 Sep 2007 08:42:52 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 08:44:25 GMT]]></title><description><![CDATA[<p>ähm ja ich weis es ja aber da gabs ne Funktion die das macht es sind 180 durchläufe.</p>
<p>Aber ich würde gern wissen wie die Funktion geht also die zählt wie oft die Schleife durchläuft das die Frage.</p>
<p>@ Braunstein: Das sieht ja schon vielversprechend aus danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1359989</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1359989</guid><dc:creator><![CDATA[GT]]></dc:creator><pubDate>Thu, 06 Sep 2007 08:44:25 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 08:55:45 GMT]]></title><description><![CDATA[<p>Was nun aber dagegen spricht, das ganze einfach auszurechnen, versteh ich immer noch nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360002</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360002</guid><dc:creator><![CDATA[Taschenrechner]]></dc:creator><pubDate>Thu, 06 Sep 2007 08:55:45 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 09:02:51 GMT]]></title><description><![CDATA[<p>@ Taschenrechner mit dem namen ists verständlich das du ausrechnen willst nein spaß</p>
<p>also ich solls so machen das spricht dagegen und das programm soll flexibel sein also ich muss die schritte verändern können und dann doch schnell wieder die anzahl bekommen. Deswegen ist es mit der Größen angabe sinvoller.</p>
<p>aber ich habs noch ned hinbekommen von nem Vektor schon aber ned von der schleife wenn ichs so mach wie oben krieg ich fehler.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360010</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360010</guid><dc:creator><![CDATA[GT]]></dc:creator><pubDate>Thu, 06 Sep 2007 09:02:51 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 09:13:07 GMT]]></title><description><![CDATA[<p>GT schrieb:</p>
<blockquote>
<p>aber ich habs noch ned hinbekommen von nem Vektor schon aber ned von der schleife wenn ichs so mach wie oben krieg ich fehler.</p>
</blockquote>
<p>Naja, schade. Aber das wird schon noch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360025</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360025</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Thu, 06 Sep 2007 09:13:07 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 09:23:28 GMT]]></title><description><![CDATA[<p><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=":confused:"
      alt="😕"
    /> das size_t versteh ich nicht !!!</p>
<p>mit counter ist mir klar aber das size blick ich nicht durch vorallem wenn man danach sucht gibts so viele treffer.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360035</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360035</guid><dc:creator><![CDATA[GT]]></dc:creator><pubDate>Thu, 06 Sep 2007 09:23:28 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 09:31:00 GMT]]></title><description><![CDATA[<p>size_t ist nur ein Typ der normalerweise unsigned int entspricht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360043</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360043</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Thu, 06 Sep 2007 09:31:00 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 09:31:01 GMT]]></title><description><![CDATA[<p>GT schrieb:</p>
<blockquote>
<p><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=":confused:"
      alt="😕"
    /> das size_t versteh ich nicht !!!</p>
</blockquote>
<p>Wenn man über allozierte Felder iteriert, muß man immer size_t nehmen, da nur so garantiert ist, daß auch alle Elemente durchlaufen werden.<br />
Es gilt z.B. auf einem 64Bit UNIX sizeof(int) == 4 und sizeof(size_t) == 8.<br />
Im konkreten Fall ist es egal, aber als Stilübung ist es besser sich das zu merken.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360044</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360044</guid><dc:creator><![CDATA[*john 0]]></dc:creator><pubDate>Thu, 06 Sep 2007 09:31:01 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 09:38:50 GMT]]></title><description><![CDATA[<p>ok jetzt ists schon klarer.</p>
<p>danke.</p>
<p>Ich glaub ich hab jetzt ne Möglichkeit es besser zu beschreiben. Es gibt ne möglichkeit sich den Belegten Speicher anzeigen zu lassen der von der schleife verwendet wird. Das wär auch wichtig für mich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360047</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360047</guid><dc:creator><![CDATA[GT]]></dc:creator><pubDate>Thu, 06 Sep 2007 09:38:50 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 10:56:55 GMT]]></title><description><![CDATA[<p>hey hab ne idee^^</p>
<p>könnte ich nicht den inhalt der schleife als vektor machen? und das kann ich mir dann anzeigen lasse wie viel es ist ? das weis ich dann wies geht</p>
<p>aber wie oft sie durchläuft weis ich immernoch nicht wie die funktion heist glaub was mit size aber des mit einen Zähler einbauen so soll ichs nicht machen naja.</p>
<p>Wenn wer die funktion weis wer ich ihm sehr verbunden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360122</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360122</guid><dc:creator><![CDATA[GT]]></dc:creator><pubDate>Thu, 06 Sep 2007 10:56:55 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 11:20:02 GMT]]></title><description><![CDATA[<p>GT schrieb:</p>
<blockquote>
<p>aber wie oft sie durchläuft weis ich immernoch nicht wie die funktion heist glaub was mit size aber des mit einen Zähler einbauen so soll ichs nicht machen naja.</p>
</blockquote>
<p>waszumgeierwillstdukennstdupunktundkommasowiegrossundkleinschreibungodernichtnaja?</p>
<p>In Ernst: Was für eine Funktion sollte es geben, um die Durchläufe einer Schleife zu zählen? Lass einen Zähler mitlaufen, wenn das Schleifenende unbestimmt ist, ansonsten rechne es aus. Es gibt keine &quot;funktion glaub irgendwas mit size&quot;, die &quot;Schleifendurchläufe&quot; &quot;zählt&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360143</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360143</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Thu, 06 Sep 2007 11:20:02 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 11:22:04 GMT]]></title><description><![CDATA[<pre><code>for( int phi = 10; phi &lt; 180; phi += 10 )  // bei dieser schleife wie krieg ich raus das sie 308 mal durchläuft
    {
        for( int theta = 0; theta &lt; 360; theta += 20 )
        {
            double x = r * cos_d(theta) * sin_d(phi);
             myFile &lt;&lt; x &lt;&lt;&quot; &quot;;
            double y = r * sin_d(theta) * sin_d(phi);
             myFile &lt;&lt; y &lt;&lt; &quot; &quot;;
            double z = r * cos_d(phi);
             myFile &lt;&lt; z &lt;&lt; &quot;\n&quot;;
        }
    }
</code></pre>
<p>Mag jetzt an mir liegen, aber geht die schleife nicht maximal 17 mal?</p>
<p>Und selbst wenn verstehe ich das problem mit dem mitzählen nicht. was soll denn daran so schlimm sein?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360144</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360144</guid><dc:creator><![CDATA[Rontha]]></dc:creator><pubDate>Thu, 06 Sep 2007 11:22:04 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 11:23:07 GMT]]></title><description><![CDATA[<p>Ihr scheint ja alle sehr auf die Schreibweise zu achten. Tut mir leid das ich das immernoch nicht richtig mache.</p>
<p>Ok dann gibts das nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360147</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360147</guid><dc:creator><![CDATA[GT]]></dc:creator><pubDate>Thu, 06 Sep 2007 11:23:07 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 11:29:13 GMT]]></title><description><![CDATA[<p>stimmt schon, kommen halt 308 werte raus sorry.</p>
<p>Aber ich kann doch sicher auslesen, dass die Schleife 308 werte drin stehen hat? Ohne es auszurechen, in dem ich den Speicher oder so abfrage?</p>
<p>Und mir dann den Wert 308 ausgeben lasse weil die Schleife 308 Werte drin stehen hat, geht das?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360154</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360154</guid><dc:creator><![CDATA[GT]]></dc:creator><pubDate>Thu, 06 Sep 2007 11:29:13 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 11:41:33 GMT]]></title><description><![CDATA[<p>So</p>
<pre><code class="language-cpp">int counter =0;
for( int phi = 10; phi &lt; 180; phi += 10 )  // bei dieser schleife wie krieg ich raus das sie 308 mal durchläuft
    {
        for( int theta = 0; theta &lt; 360; theta += 20 )
        {
            double x = r * cos_d(theta) * sin_d(phi);
             myFile &lt;&lt; x &lt;&lt;&quot; &quot;;
            double y = r * sin_d(theta) * sin_d(phi);
             myFile &lt;&lt; y &lt;&lt; &quot; &quot;;
            double z = r * cos_d(phi);
             myFile &lt;&lt; z &lt;&lt; &quot;\n&quot;;
           counter ++;  
        }

    }

cout &lt;&lt; &quot;Schleifeiterationen: &quot; &lt;&lt; counter &lt;&lt; &quot; &quot;  ;
system(&quot;pause&quot;);
</code></pre>
<p>Da kommt jetzt 306 raus was richtig ist, da es 306 Punkte sind. Die beiden Letzten Punkte sind ganz oben und ganz unten zum eintragen. Damit hab ich meine 308.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360161</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360161</guid><dc:creator><![CDATA[GT]]></dc:creator><pubDate>Thu, 06 Sep 2007 11:41:33 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 11:45:05 GMT]]></title><description><![CDATA[<p>Bietet bitte mal Kurse &quot;Wie drücke ich aus, was ich WIRKLICH will&quot; an.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360162</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360162</guid><dc:creator><![CDATA[OMG]]></dc:creator><pubDate>Thu, 06 Sep 2007 11:45:05 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 11:46:51 GMT]]></title><description><![CDATA[<p>Die Schleife hat nicht 308 Werte drinstehen, sondern sie wird 308 mal durchlaufen. Hat aber jedesmal nur einen einzelnen Wert drinstehen (oder 3, wenn du 3 Variablen drin hast).<br />
Was die Schreibweise angeht:<br />
Wenn man einen Satz lesen muss, der ohne Punkt und Komma geschrieben ist, oder der, wie bei anderen oft gesehen, von Grammatik- und Rechtschreibfehlern trieft, dann behindert das den Lesefluss. Die Leute muessen mehr Konzentration ins reine Lesen investrieren und weniger in das angesprochene Problem. Und da du derjenige bist, der Hilfe haben moechte, ists in deinem eigenen Interesse, das zu verhindern. Denn irgendwann ist den Leuten das zu nervig und sie lesens garnicht mehr. Also ists nur gut, wenn sie an deinem Schreibstil rummaekeln, anstatt es gleich dranzugeben und dich im Regen stehen zu lassen <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/1360164</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360164</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 06 Sep 2007 11:46:51 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 12:12:19 GMT]]></title><description><![CDATA[<p>Ja ich bin halt nicht sonderlich gut in Gramatik und Rechtschreibung. Tut mir echt<br />
Leid.</p>
<p>Was die 308 betrifft meinte ich ja das sie 306 mal durchläuft und immer 3 Werte reinschreibt. Und die letzten 2 Werte schreib ich dann manuell rein.</p>
<p>Und man kann das echt nicht anderster rauskriegen die 306?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360169</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360169</guid><dc:creator><![CDATA[GT]]></dc:creator><pubDate>Thu, 06 Sep 2007 12:12:19 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 11:57:05 GMT]]></title><description><![CDATA[<p>GT schrieb:</p>
<blockquote>
<p>...die letzten 2 Werte schreib ich dann Manuel rein....</p>
</blockquote>
<p>Was kann der arme Manuel denn dafür ? <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>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360171</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360171</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Thu, 06 Sep 2007 11:57:05 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 12:19:43 GMT]]></title><description><![CDATA[<p>GT schrieb:</p>
<blockquote>
<p>Und man kann das echt nicht anderster rauskriegen die 306?</p>
</blockquote>
<p>Nunja, dir wurden bisher zwei Moeglichkeiten genannt:</p>
<p>a) Zehler mitlaufen lassen, dann weisst dus hinterher.<br />
b) Wenn alle Bedingungen vorher bekannt sind (wie in deinem Fall hier), einfach ausrechnen wie oft die Schleife durchaufen wird. In deinem Fall sinds geschachtelte Zaehlschleifen, die Zaehlvariable wird nicht geaendert, also ist die jeweilige Anzahl der Durchlaeufe nur abhaengig vom Startwert, Endwert und der Schrittweite. Die Rechnung dazu ist folgene:</p>
<pre><code class="language-cpp">int min, max, step; //startwert, endwert, schrittweite
int nloop = (max - min - 1)/step + 1;
if (nloop &lt; 1) nloop = 1;
</code></pre>
<p>Die letzte Abfrage tritt nur in Kraft, wenn max &lt; min ist, sonst wuerden da negative Werte rauskommen, was nicht gut moeglich ist. Die Schleife wird schliesslich mindestens einmal durchlaufen.<br />
Jetzt berechnet man nloop fuer die innere und aeussere Schleife und mitlipliziert das ganze miteinander. Spezialisiert auf deinen Fall, wo ja nur die Schrittweite fuer phi und theta veraenderbar sind, kommt dann folgendes bei raus:</p>
<pre><code class="language-cpp">int step_phi, step_theta;
int nloop, nloop_phi, nloop_theta;
step_phi = /*20*/;
step_theta = /*10*/;

nloop_phi = 359/step_phi + 1; // = 17 + 1 = 18
nloop_theta = (179-step_theta)/step_theta + 1; // = 16 + 1 = 17
nloop = nloop_theta + nloop_phi; // = 17 * 18 = 306

//deine Schleife:
for( int theta = step_theta; theta &lt; 180; theta += step_theta )  
    {
        for( int phi = 0; phi &lt; 360; phi += ste_phi )
        {
        //...
        }
    }
</code></pre>
<p>Ich hab mir mal die Freiheit rausgenommen, die Kugelkoordinaten theta und phi so zu benutzen wie sie normalerweise benutzt werden, wie ich oben schon geschrieben hatte hast du das vertauscht <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>
<p>Verscuh meinen Fetzen mal mit anderen Werten fuer step_theta und step_phi, du wirst sehn dass genau die richtige Zahl an loops bei rauskommt, wenn du den counter noch drinlaesst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360184</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360184</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 06 Sep 2007 12:19:43 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 12:34:37 GMT]]></title><description><![CDATA[<p>Danke für die Erklärung. <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>
<p>Ok das probier ich aus! Aber wenigstens ists mir beim lesen jetzt schon klar.</p>
<p>Du hast dich da verschrieben</p>
<pre><code class="language-cpp">nloop = nloop_theta + nloop_phi; // = 17 * 18 = 306
</code></pre>
<p>ist * nicht +</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360189</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360189</guid><dc:creator><![CDATA[GT]]></dc:creator><pubDate>Thu, 06 Sep 2007 12:34:37 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 12:53:48 GMT]]></title><description><![CDATA[<p>Aber wenn du sagst theta und phi ist verdreht. Ist dann die Rechnung noch richtig?</p>
<p>double x = radius * cos(theta) * sin(phi);</p>
<p>double y = radius * sin(theta) * sin(phi);</p>
<p>double z = radius * cos(phi);</p>
<p>bzw.</p>
<p>x = r * cos_d(0) * sin_d(180);</p>
<p>y = r * sin_d(0) * sin_d(180);</p>
<p>z = r * cos_d(180);</p>
<p>muss ich dann die werte in den Klammern tauschen?<br />
dann kommen aber andere ergebnisse raus die dann keien Kugel mehr ergeben bzw. ein Punkt ist anders.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360200</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360200</guid><dc:creator><![CDATA[GT]]></dc:creator><pubDate>Thu, 06 Sep 2007 12:53:48 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann man zählen wie oft eine schleife durchläuft? on Thu, 06 Sep 2007 14:47:08 GMT]]></title><description><![CDATA[<p>Natuerlich musst du auch da dann theta und phi vertauschen. So wie dus vorher gemacht hast kam natuerlich das richtige bei raus, du hast halt den Winkel, der von Pol zu Pol geht, phi genannt, und den Winkel in der x-y-Ebene theta. In jedem Fetzen Literatur, der in irgendeiner Art mit Kugelkoordinaten umgeht, wirds aber genau andersrum gehandhabt. Ist halt kein Muss, aber Konvention, und wenn man sich an die haelt kommt man nicht durcheinander wenn man ploetzlich was anderes liest <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>
<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>z</mi><mo>=</mo><mi>r</mi><mi>cos</mi><mo>(</mo><mi>ϑ</mi><mo>)</mo><mspace width="2em"></mspace><mi>y</mi><mo>=</mo><mi>r</mi><mi>sin</mi><mo>(</mo><mi>ϑ</mi><mo>)</mo><mi>sin</mi><mo>(</mo><mi>φ</mi><mo>)</mo><mspace width="2em"></mspace><mi>x</mi><mo>=</mo><mi>r</mi><mi>sin</mi><mo>(</mo><mi>ϑ</mi><mo>)</mo><mi>cos</mi><mo>(</mo><mi>φ</mi><mo>)</mo></mrow><annotation encoding="application/x-tex">z = r \cos(\vartheta)\qquad  
y = r \sin(\vartheta)\sin(\varphi)\qquad  
x = r \sin(\vartheta)\cos(\varphi)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base displaystyle textstyle uncramped"><span class="mord mathit" style="margin-right:0.04398em;">z</span><span class="mrel">=</span><span class="mord mathit" style="margin-right:0.02778em;">r</span><span class="mop">cos</span><span class="mopen">(</span><span class="mord mathit">ϑ</span><span class="mclose">)</span><span class="mord mspace qquad"></span><span class="mord mathit" style="margin-right:0.03588em;">y</span><span class="mrel">=</span><span class="mord mathit" style="margin-right:0.02778em;">r</span><span class="mop">sin</span><span class="mopen">(</span><span class="mord mathit">ϑ</span><span class="mclose">)</span><span class="mop">sin</span><span class="mopen">(</span><span class="mord mathit">φ</span><span class="mclose">)</span><span class="mord mspace qquad"></span><span class="mord mathit">x</span><span class="mrel">=</span><span class="mord mathit" style="margin-right:0.02778em;">r</span><span class="mop">sin</span><span class="mopen">(</span><span class="mord mathit">ϑ</span><span class="mclose">)</span><span class="mop">cos</span><span class="mopen">(</span><span class="mord mathit">φ</span><span class="mclose">)</span></span></span></span></span></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1360304</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1360304</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 06 Sep 2007 14:47:08 GMT</pubDate></item></channel></rss>