# Staring at loops

**URL:** <https://forum.csound.com/t/staring-at-loops/1498>\
**Category:** General\
**Created:** [January 7, 2024, 8:59pm UTC](https://forum.csound.com/t/staring-at-loops/1498 "2024-01-07T20:59:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tjingboem](https://forum.csound.com/user_avatar/forum.csound.com/tjingboem/32/44_2.png) [@tjingboem](https://forum.csound.com/u/tjingboem)\
**Post date:** [January 7, 2024, 8:59pm UTC](https://forum.csound.com/t/staring-at-loops/1498/1 "2024-01-07T20:59:11Z")

</div>

hi all,  
i have this head breaker puzzle that i can use help in solving. I have been staring at it and trying a few hours now and my vision has become blurred.  
It has to do with a loop in a loop.

i’m afraid to show one of my test codes here, because i know this is (very) bad…  
Perhaps for someone this is a piece of cake?

What is my goal: create an i-rate loop.

- have ixstart loop and print it (ixstart += 1) until it has reached 5- i know this one
- then move on and add 2 to it. That makes it 7- doable as well
- go back and do this 3 times (or more)- now things start to blur…

the result should be: 1,2,3,4,5, 7,8,9,10,11, 13,14,15,16,17, …etc

(Under pressure i am willing to show my bad code)

---

<div class="post-metadata">

**Author:** ![joachim](https://forum.csound.com/letter_avatar_proxy/v4/letter/j/a87d85/32.png) [@joachim](https://forum.csound.com/u/joachim)\
**Post date:** [January 7, 2024, 9:25pm UTC](https://forum.csound.com/t/staring-at-loops/1498/2 "2024-01-07T21:25:30Z")

</div>

hi menno -  
something like this? best -  
joachim

instr 1  
iStart = 1  
iNumLoops = 5  
iThisLoop = 0  
iArr[] init 5  
while (iThisLoop \< iNumLoops) do  
indx = 0  
while (indx \< 5) do  
iArr[indx] = iStart+indx  
indx += 1  
od  
printarray(iArr)  
iThisLoop += 1  
iStart += 6  
od  
endin

---

<div class="post-metadata">

**Author:** ![joachim](https://forum.csound.com/letter_avatar_proxy/v4/letter/j/a87d85/32.png) [@joachim](https://forum.csound.com/u/joachim)\
**Post date:** [January 7, 2024, 9:46pm UTC](https://forum.csound.com/t/staring-at-loops/1498/3 "2024-01-07T21:46:23Z")

</div>

hmm indendation is ruined in the email — so here once again attached.

[test2.csd](https://forum.csound.com/uploads/short-url/73dMAHU25TyVZyUfxOh7kbZZ5IY.csd) (713 Bytes)

---

<div class="post-metadata">

**Author:** ![tjingboem](https://forum.csound.com/user_avatar/forum.csound.com/tjingboem/32/44_2.png) [@tjingboem](https://forum.csound.com/u/tjingboem)\
**Post date:** [January 9, 2024, 2:40pm UTC](https://forum.csound.com/t/staring-at-loops/1498/4 "2024-01-09T14:40:39Z")

</div>

Great code, but not what i was looking for 😊  
although i can see the beauty of using arrays, it also obliges me to study how arrays work before continuing the project i am working on. Maybe this is the time for this study, because one thing leads to another…not sure yet.

I was hoping / looking for something more old skool, so code based on adding and loops without arrays.

So output should be, if 5 values are to be printed, the 6th skipped, then go on counting another 5 starting at 7, skip one value after 11 , etc etc until i say: stop at 100 for example  
1,2,3,4,5, 7,8,9,10,11, 13,14,15,16,17, 19,20,21,22,23, 25…100

I think this would take yet another loop construction to replace the counting of the array.  
I will start by creating one loop and looping that loop. If i still understand what is happening, i will add yet another loop.

Thanks, Joachim, for your code.  
I fear the come has come to start the array study 😀 I am sure it will pay off in the long run

---

<div class="post-metadata">

**Author:** ![joachim](https://forum.csound.com/letter_avatar_proxy/v4/letter/j/a87d85/32.png) [@joachim](https://forum.csound.com/u/joachim)\
**Post date:** [January 9, 2024, 5:32pm UTC](https://forum.csound.com/t/staring-at-loops/1498/5 "2024-01-09T17:32:33Z")

</div>

yeah if it is only about printing, the solution without arrays is  
perhaps simpler.  
we can count from 1 to 100 and after 5 values stop printing for one number.  
not sure i missed something, but you can compare the code attached.

[test2.csd](https://forum.csound.com/uploads/short-url/innFS0Na5o5hCu8HCj5VnWRYMqg.csd) (1.28 KB)

---

<div class="post-metadata">

**Author:** ![tjingboem](https://forum.csound.com/user_avatar/forum.csound.com/tjingboem/32/44_2.png) [@tjingboem](https://forum.csound.com/u/tjingboem)\
**Post date:** [January 9, 2024, 6:11pm UTC](https://forum.csound.com/t/staring-at-loops/1498/6 "2024-01-09T18:11:41Z")

</div>

wow, you really control this. Nice to see.

This is definitely better readable for me. And a soft introduction to the array world. Thanks!  
Something to build upon.

---

<div class="post-metadata">

**Author:** ![joachim](https://forum.csound.com/letter_avatar_proxy/v4/letter/j/a87d85/32.png) [@joachim](https://forum.csound.com/u/joachim)\
**Post date:** [January 10, 2024, 8:20am UTC](https://forum.csound.com/t/staring-at-loops/1498/7 "2024-01-10T08:20:38Z")

</div>

your question was interesting for me, too.  
meanwhile i realized that there is a much simpler version with arrays:

instr 1  
iNumbers[] = fillarray(1,2,3,4,5)  
while (iNumbers[0] \< 100) do  
printarray(iNumbers)  
iNumbers += 6  
od  
endin  
schedule(1,0,0)

perhaps even more motivation for you to approach this field. and cs7  
will probably offer some new facilities.

j

---

<div class="post-metadata">

**Author:** ![tjingboem](https://forum.csound.com/user_avatar/forum.csound.com/tjingboem/32/44_2.png) [@tjingboem](https://forum.csound.com/u/tjingboem)\
**Post date:** [January 10, 2024, 8:41am UTC](https://forum.csound.com/t/staring-at-loops/1498/8 "2024-01-10T08:41:34Z")

</div>

this is close to art, Joachim.  
The aesthetics of it is yet another motivation!
