Split and loop in dial plan

Hi all,
I’m looking to achieve something that is very simple in an ECMA based script like Javascript.

Consider this pseudo code:

s = "1,2,3,4" a = s.split(",") for(n=0; n<a.length; n++){ // do something with a[n] }
Now, how would you do the same in Asterisk Dial plan?

e.g. (AEL):

for (x=0; ${x}<${FIELDQTY(test,\,)};x=${x}+1) {
    // do something with tmp (equivalent to a[n])

e.g. (conf-style):

exten => s,1,Set(test=1,2,3,4)
exten => s,n,MSet(x=$[0])
exten => s,n(next),GotoIf($[ ${x}<${FIELDQTY(test,\,)}]?dosomething:continue)
exten => s,n(dosomething),Set(tmp=${CUT(test,,,$[${x}+1])})
// do something with tmp (equivalent to a[n])
exten => s,n,MSet(x=$[${x}+1])
exten => s,n,Goto(next)
exten => s,n(continue),NoOp(End of Loop)

It must work if s = “1” or s = “1,2”

EDIT: conf-style