[Asterisk-Users] Loops and Variables
Tzafrir Cohen
tzafrir at cohens.org.il
Tue Feb 21 00:15:45 MST 2006
On Mon, Feb 20, 2006 at 10:14:55AM -0700, Douglas Garstang wrote:
> It was trying to perform looping in the dialplan that made me seriously look at AGI. Gee, I wonder what's easier.
>
> This:
> exten => s,1,Set(COUNT=0)
> exten => s,2,Goto(loop,1);this is where we start the loop
> exten => loop,1,GotoIf($[${COUNT} > 5]?next,1);exit if more than 5 esle start again
> exten => loop,2,Set(COUNT=$[${COUNT} + 1])
> exten => loop,3,Goto(1)
> exten => next,1,Noop(${COUNT})
>
> or this...
> loop = 0
> while loop < 5:
> do-something
It's the "do something" that will become more complicated. Not to
mention the overhead (specifically latency) of firing an extra interpeter
on every call. And chances are you'll end up with 3 or 4 such AGIs per
call with such an attitiude.
> loop += 1
>
> I really wasn't enthused about having to look at dialplan code months later and try and work out what I did earlier.
> Nasty!
Note that I wasn't using some newer 1.2 syntax. With it it could be:
> exten => s,1,Set(COUNT=0)
> exten => s,n,Goto(loop,1);this is where we start the loop
>
> exten => loop,1,GotoIf($[${COUNT} > 5] ? next,1)
> exten => loop,n,Set(COUNT=$[${COUNT} + 1])
> exten => loop,n,Goto(1)
>
> exten => next,1,Noop(${COUNT})
Not to mention AEL, which I have not began to explore.
>
>
> -----Original Message-----
> From: Tzafrir Cohen [mailto:tzafrir at cohens.org.il]
> Sent: Monday, February 20, 2006 9:14 AM
> To: asterisk-users at lists.digium.com
> Subject: Re: [Asterisk-Users] Loops and Variables
>
>
> On Mon, Feb 20, 2006 at 08:56:41AM -0500, C F wrote:
> > I usually do the same for IVRs, but I always make sure not to use
> > itself as the increment, and I use a tempvar instead, like this:
>
> Why?
>
> > exten => s,1,Set(COUNT=0)
> > exten => s,2,Goto(100);this is where we start the loop
> > exten => s,100,Set(TCOUNT=${COUNT})
> > exten => s,101,Noop(${COUNT})
> > exten => s,102,GotoIf($[${COUNT} > 5]?150);exit if more than 5 esle start again
> > exten => s,103,Set(COUNT=$[{TCOUNT} + 1])
> > exten => s,104,Goto(100)
> > exten => s,150,Noop(${COUNT})
>
> Why not simply:
>
> > exten => s,1,Set(COUNT=0)
> > exten => s,2,Goto(100);this is where we start the loop
> > exten => s,100,GotoIf($[${COUNT} > 5]?150);exit if more than 5 esle start again
> > exten => s,101,Set(COUNT=$[${COUNT} + 1])
> > exten => s,102,Goto(100)
> > exten => s,150,Noop(${COUNT})
>
> Alternatively:
>
> > exten => s,1,Set(COUNT=0)
> > exten => s,2,Goto(loop,1);this is where we start the loop
> > exten => loop,1,GotoIf($[${COUNT} > 5]?next,1);exit if more than 5 esle start again
> > exten => loop,2,Set(COUNT=$[${COUNT} + 1])
> > exten => loop,3,Goto(1)
> > exten => next,1,Noop(${COUNT})
>
> --
> Tzafrir Cohen | tzafrir at jbr.cohens.org.il | VIM is
> http://tzafrir.org.il | | a Mutt's
> tzafrir at cohens.org.il | | best
> ICQ# 16849755 | | friend
>
> _______________________________________________
> --Bandwidth and Colocation provided by Easynews.com --
>
> Asterisk-Users mailing list
> To UNSUBSCRIBE or update options visit:
> http://lists.digium.com/mailman/listinfo/asterisk-users
> _______________________________________________
> --Bandwidth and Colocation provided by Easynews.com --
>
> Asterisk-Users mailing list
> To UNSUBSCRIBE or update options visit:
> http://lists.digium.com/mailman/listinfo/asterisk-users
--
Tzafrir Cohen | tzafrir at jbr.cohens.org.il | VIM is
http://tzafrir.org.il | | a Mutt's
tzafrir at cohens.org.il | | best
ICQ# 16849755 | | friend
More information about the asterisk-users
mailing list