[Asterisk-Users] Unexpected results with "While" and "EndWhile"
applications
C F
shmaltz at gmail.com
Mon Sep 5 20:39:59 MST 2005
On 9/5/05, John Todd <jtodd at loligo.com> wrote:
>
> I seem to be having a conceptual problem with the "While" and
> "EndWhile" applications. It seems that on the first cycle, even if
> the result of the "While" is false that the enclosed applications
> will get run. Is this expected? It seems to be counter-intuitive,
> but I don't know what the intent of the While routines is. I could
> of course put a "GotoIf" before the While loop to check to ensure
> that the first expression is true before entry into the While loop,
> but that seems redundant and ugly since the while point of While and
> EndWhile is to avoid the inelegance of GotoIf, I thought.
>
> If anyone can't come up with a better explanation, I'll open a ticket
> on this but I'd like to first make sure that this behavior is not
> expected.
>
>
> exten => 2231,1,Set(staticnumber=0)
> exten => 2231,n,Set(counter=1)
> exten => 2231,n,While($["${counter}"<"${staticnumber}"])
Put A space around the < operator, like this
exten => 2231,n,While($["${counter}" < "${staticnumber}"])
This should help it.
> exten => 2231,n,NoOp("This part of the code should never run!")
> exten => 2231,n,Set(counter=$[${counter}+1])
> exten => 2231,n,EndWhile
> exten => 2231,n,NoOp("This part of the code should be the only thing
> that gets run!")
>
>
> Console output from dialing 2231:
>
> -- Executing Set("SIP/2203-c134", "staticnumber=0") in new stack
> -- Executing Set("SIP/2203-c134", "counter=1") in new stack
> -- Executing While("SIP/2203-c134", "0") in new stack
> -- Executing NoOp("SIP/2203-c134", ""This part of the code should
> never run!"") in new stack
> -- Executing Set("SIP/2203-c134", "counter=2") in new stack
> -- Executing EndWhile("SIP/2203-c134", "") in new stack
> -- Executing NoOp("SIP/2203-c134", ""This part of the code should
> be the only thing that gets run!"") in new stack
> *CLI> show version
> Asterisk CVS HEAD built by root at some.host.com on a i686 running Linux
> on 2005-09-03 23:27:34 UTC
>
> JT
> _______________________________________________
> --Bandwidth and Colocation sponsored by Easynews.com --
>
> Asterisk-Users mailing list
> Asterisk-Users at lists.digium.com
> http://lists.digium.com/mailman/listinfo/asterisk-users
> To UNSUBSCRIBE or update options visit:
> http://lists.digium.com/mailman/listinfo/asterisk-users
>
More information about the asterisk-users
mailing list