<?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[Anfänger Frage wegen Schleife [gelöst]]]></title><description><![CDATA[<p>Hi,</p>
<p>ich würde gerne eine Schleife schreiben die mir in ein Array immer wieder eine Bestimmte abfolge von zahlen schreibt.</p>
<p>Ungefähr so:</p>
<p>arrayindex 1: 0<br />
arrayindex 2: 1<br />
arrayindex 3: 2<br />
arrayindex 4: 0<br />
arrayindex 5: 1<br />
arrayindex 6: 2</p>
<p>usw.</p>
<p>Nur krieg ich das irgendwie nicht hin.</p>
<p>Hier mein ansatz:</p>
<pre><code class="language-cpp">for(int k = 0; k &lt; (x * y);   k++)
    {
      if(k &lt; (x * y ))
      {
        for(int j = 0; j &lt; x; j ++)
        {
          pxMap[k] = j;
        }
      }
    }
</code></pre>
<p>Nur klappt das nicht.</p>
<p>Für Hilfe wäre ich sehr dankbar</p>
<p>Gruß</p>
<p>GT</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/212140/anfänger-frage-wegen-schleife-gelöst</link><generator>RSS for Node</generator><lastBuildDate>Wed, 14 Oct 2026 18:56:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/212140.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 02 May 2008 11:02:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Anfänger Frage wegen Schleife [gelöst] on Mon, 05 May 2008 06:05:22 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich würde gerne eine Schleife schreiben die mir in ein Array immer wieder eine Bestimmte abfolge von zahlen schreibt.</p>
<p>Ungefähr so:</p>
<p>arrayindex 1: 0<br />
arrayindex 2: 1<br />
arrayindex 3: 2<br />
arrayindex 4: 0<br />
arrayindex 5: 1<br />
arrayindex 6: 2</p>
<p>usw.</p>
<p>Nur krieg ich das irgendwie nicht hin.</p>
<p>Hier mein ansatz:</p>
<pre><code class="language-cpp">for(int k = 0; k &lt; (x * y);   k++)
    {
      if(k &lt; (x * y ))
      {
        for(int j = 0; j &lt; x; j ++)
        {
          pxMap[k] = j;
        }
      }
    }
</code></pre>
<p>Nur klappt das nicht.</p>
<p>Für Hilfe wäre ich sehr dankbar</p>
<p>Gruß</p>
<p>GT</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1501971</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1501971</guid><dc:creator><![CDATA[GT]]></dc:creator><pubDate>Mon, 05 May 2008 06:05:22 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger Frage wegen Schleife [gelöst] on Fri, 02 May 2008 11:19:21 GMT]]></title><description><![CDATA[<p>einfach die zahl die zugewiesen werden soll erhoehen, und beim maximum {im beispiel 3} wieder zurueck setzen<br />
nur so ne idee</p>
<pre><code class="language-cpp">// 1-3
int j = 0
for(int k = 0; k &lt; (x * y); ++k, ++j)
{
    if(j == 4) j = 0;
    pxMap[k] = j;
}
</code></pre>
<p>btw. deine if in der schleife kannst du ignorieren, da du den fall schon durch das for ausschliesst</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1501990</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1501990</guid><dc:creator><![CDATA[EXDW]]></dc:creator><pubDate>Fri, 02 May 2008 11:19:21 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger Frage wegen Schleife [gelöst] on Fri, 02 May 2008 11:22:49 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">const int NUMBER_SEQUENCE_LENGTH = 3;
int numberSequence[NUMBER_SEQUENCE_LENGTH] = {0, 1, 2};

const int ARRAY_TO_FILL_LENGTH = 7;
int arrayToFill[ARRAY_TO_FILL_LENGTH];

for(int i = 0; i &lt; ARRAY_TO_FILL_LENGTH; i++)
{
    int numberSequenceIndexToUse = i % NUMBER_SEQUENCE_LENGTH;
    arrayToFill[i] = numberSequence[numberSequenceIndexToUse];
}
</code></pre>
<p>ich bin mir nicht sicher ob man in c++ das array initialisieren kann so direkt mit {0, 1, 2}, wenn nicht machs halt mit index dingern also blabla[0] = 0; etc</p>
<p>bzw wenn du davon ausgehen kannst dass arrayToFill immer eine länge hat die ein vielfaches von 3 ist kannst du es noch einafcher machen</p>
<pre><code class="language-cpp">const int ARRAY_TO_FILL_LENGTH = 9;
int arrayToFill[ARRAY_TO_FILL_LENGTH];

for(int i = 0; i &lt; (ARRAY_TO_FILL_LENGTH / 3); i++)
{
    arrayToFill[i * 3 + 0] = 0;
    arrayToFill[i * 3 + 1] = 1;
    arrayToFill[i * 3 + 2] = 2;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1501991</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1501991</guid><dc:creator><![CDATA[Vevusio]]></dc:creator><pubDate>Fri, 02 May 2008 11:22:49 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger Frage wegen Schleife [gelöst] on Fri, 02 May 2008 11:25:12 GMT]]></title><description><![CDATA[<p>Mal vorab: &quot;klappt nicht&quot; ist keine gültige Fehlerbeschreibung <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>dann zu deinem Code: das <code>if (k&lt; (x*y))</code> hat in dem Fall keinen Effekt, weil der Schleifenkörper sowieso nur ausgeführt wird, solange diese Bedingung gilt. Danach schreibst du die Zahlen von 0 bis x-1 in pxmap[k] rein, was bedeutet, dass du in jedes Arrayelement nacheinander die zahlen von 0 bis x-1 schreibst, da bleibt am Ende natürlich überall x-1 als Wert stehn. Ich geb mal zwei Beispiele wie es richtig zu machen wäre:</p>
<pre><code class="language-cpp">for(int k=0, l=0; k&lt;(x*y); ++k, ++l)) { //k ist der arrayindex, l die Zahl die eingetragen wird
  if(l &gt;= x) l=0;  //zurücksetzen von l wenn das maximum überschritten wird
  pxMap[k] = l;
}
</code></pre>
<p>andere Möglichkeit:</p>
<pre><code class="language-cpp">for(int k=0; k&lt;y; ++k)
  for(int j=0; j&lt;x; ++j) {
    pxMap[k*x + j] = j;
  }
</code></pre>
<p>Versuch mal, die beiden Schleifen für x=3, y=3 per Hand auf dem Papier zu machen, dann siehst du wie sie funktionieren (das ist sowieso meist die beste Methode wenn man etwas kompliziertere Zählschleifen erstellen will).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1501995</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1501995</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Fri, 02 May 2008 11:25:12 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger Frage wegen Schleife [gelöst] on Fri, 02 May 2008 11:25:33 GMT]]></title><description><![CDATA[<p>GT schrieb:</p>
<blockquote>
<p>Hi,</p>
<p>ich würde gerne eine Schleife schreiben die mir in ein Array immer wieder eine Bestimmte abfolge von zahlen schreibt.</p>
<p>Ungefähr so:</p>
<p>arrayindex 1: 0<br />
arrayindex 2: 1<br />
arrayindex 3: 2<br />
arrayindex 4: 0<br />
arrayindex 5: 1<br />
arrayindex 6: 2</p>
<p>usw.</p>
</blockquote>
<p>Wieso so kompliziert? Machs doch mit Modulo:</p>
<pre><code class="language-cpp">int dim = 15;
int array[dim];
for (int i = 0; i &lt; dim; i++)
{
   array[i] = i%3;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1501996</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1501996</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Fri, 02 May 2008 11:25:33 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger Frage wegen Schleife [gelöst] on Fri, 02 May 2008 14:26:16 GMT]]></title><description><![CDATA[<p>Ich habe da auch eine speicherschonende Lösung:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

class myarray
{
  public:
    int operator[] (int v) const  { return (v - 1) % 3; }
};

void main()
{
  myarray a;
  for (int idx = 1; idx &lt;= 15; ++idx)
    std::cout &lt;&lt; &quot;arrayindex &quot; &lt;&lt; idx &lt;&lt; &quot;: &quot; &lt;&lt; a[idx] &lt;&lt; '\n';
}
</code></pre>
<p><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/1502120</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1502120</guid><dc:creator><![CDATA[tntnet]]></dc:creator><pubDate>Fri, 02 May 2008 14:26:16 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger Frage wegen Schleife [gelöst] on Fri, 02 May 2008 14:28:36 GMT]]></title><description><![CDATA[<p>lol</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1502124</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1502124</guid><dc:creator><![CDATA[Vevusio]]></dc:creator><pubDate>Fri, 02 May 2008 14:28:36 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger Frage wegen Schleife [gelöst] on Fri, 02 May 2008 14:32:04 GMT]]></title><description><![CDATA[<p>Warum fängt bei dir arrayindex bei 1 an?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1502128</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1502128</guid><dc:creator><![CDATA[hmmmm]]></dc:creator><pubDate>Fri, 02 May 2008 14:32:04 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger Frage wegen Schleife [gelöst] on Fri, 02 May 2008 14:34:24 GMT]]></title><description><![CDATA[<p>er wollte einfach bei der ausgabe bei 1 anfangen und halt a[idx] unabsichtlich statt a[idx-1]</p>
<p>die lösung von tn ist sowieso blos als witz gedacht so wie ich das sehe <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/1502132</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1502132</guid><dc:creator><![CDATA[Vevusio]]></dc:creator><pubDate>Fri, 02 May 2008 14:34:24 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger Frage wegen Schleife [gelöst] on Fri, 02 May 2008 14:35:01 GMT]]></title><description><![CDATA[<p>Viel schlimmer (manche lernens wohl nie):</p>
<p>tntnet schrieb:</p>
<blockquote>
<pre><code class="language-cpp">void main()
</code></pre>
</blockquote>
<p><code>main()</code> gibt einen <strong>Integer</strong> zurück! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1502133</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1502133</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Fri, 02 May 2008 14:35:01 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger Frage wegen Schleife [gelöst] on Mon, 05 May 2008 06:04:58 GMT]]></title><description><![CDATA[<p>Vielen dank für die Hilfe.</p>
<p>Habs dann selber gelöst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1503397</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1503397</guid><dc:creator><![CDATA[GT]]></dc:creator><pubDate>Mon, 05 May 2008 06:04:58 GMT</pubDate></item></channel></rss>