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

2005-09-05 Thread John Todd


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}"])
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 [EMAIL PROTECTED] 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@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


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

2005-09-05 Thread C F
On 9/5/05, John Todd <[EMAIL PROTECTED]> 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 [EMAIL PROTECTED] 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@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
>
___
--Bandwidth and Colocation sponsored by Easynews.com --

Asterisk-Users mailing list
Asterisk-Users@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


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

2005-09-05 Thread John Todd

At 11:39 PM -0400 on 9/5/05, C F wrote:

On 9/5/05, John Todd <[EMAIL PROTECTED]> 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 [EMAIL PROTECTED] 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@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