Csound Csound-dev Csound-tekno Search About

[Csnd-dev] for-loop over audio vector

Date2025-08-13 13:20
Fromjoachim heintz
Subject[Csnd-dev] for-loop over audio vector
i am testing the for-loop in different situations and found this:

with a while loop i can do
instr 1
   aSin = poscil(1,100)
   kndx = 0
   while (kndx < ksmps) do
     printk2(aSin[kndx])
     kndx += 1
   od
   turnoff
endin

but with a for-loop ...
instr 2
   aSin = poscil(1,100)
   for kndx in aSin do
     printk2(aSin[kndx])
   od
   turnoff
endin
... i get the error:
invalid argument in for statement: found 'aSin', which is not an array

should this not work?

Date2025-08-13 15:40
Fromvlz
SubjectRe: [Csnd-dev] for-loop over audio vector
You need an array in for loops, aSin is an asig.

Prof. Victor Lazzarini
Maynooth University
Ireland

> On 13 Aug 2025, at 09:20, joachim heintz  wrote:
> 
> i am testing the for-loop in different situations and found this:
> 
> with a while loop i can do
> instr 1
>  aSin = poscil(1,100)
>  kndx = 0
>  while (kndx < ksmps) do
>    printk2(aSin[kndx])
>    kndx += 1
>  od
>  turnoff
> endin
> 
> but with a for-loop ...
> instr 2
>  aSin = poscil(1,100)
>  for kndx in aSin do
>    printk2(aSin[kndx])
>  od
>  turnoff
> endin
> ... i get the error:
> invalid argument in for statement: found 'aSin', which is not an array
> 
> should this not work?