[Asterisk-Users] Loops and Variables
Tzafrir Cohen
tzafrir at cohens.org.il
Mon Feb 20 09:14:11 MST 2006
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
More information about the asterisk-users
mailing list