[Asterisk-Users] Unexpected results with "While" and "EndWhile" applications

John Todd jtodd at loligo.com
Mon Sep 5 23:08:12 MST 2005


At 11:39 PM -0400 on 9/5/05, C F wrote:
>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.

That's no longer required in CVS-HEAD, if I recall correctly.

In any case, this does not make a difference, and even looking 
logically at the example shows that it is not behaving correctly. (It 
parses correctly on the second instance, but not on the first.)

This is looking more like a bug the longer I think about it.

JT

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



More information about the asterisk-users mailing list