[Asterisk-Users] Loops and Variables

C F shmaltz at gmail.com
Tue Feb 21 20:03:50 MST 2006


On 2/20/06, Tzafrir Cohen <tzafrir at cohens.org.il> wrote:
> 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?

Because when I first created my loop code, I ran into trouble when
trying to increment by itself, I can't remember what it was, but I do
remember that using a temp fixed it. But you are right if it works
then there is no need to use a temp.

>
> > 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
>



More information about the asterisk-users mailing list