Summary:ASTERISK-06810: nested while loops dont return to parent loop when you goto() out of the child loop
Reporter:furiousgeorge (furiousgeorge)Labels:
Date Opened:2006-04-18 23:19:54Date Closed:2006-04-26 13:50:22
Versions:Frequency of
Environment:Attachments:( 0) 20060419__bug6994.diff.txt
( 1) 20060421__more_while_stuff.diff.txt
exten => s,1,set(COUNT=1)
exten => s,n,while($[${COUNT}=1])
exten => s,n,while(1)
exten => s,n,goto(exit)
exten => s,n,endwhile
exten => s,n(exit),set(COUNT=2)
exten => s,n,endwhile


I see why this isn't working.  Perhaps it should be documented not to use goto() to a parent while from a nested while.
Comments:By: Tilghman Lesher (tilghman) 2006-04-19 00:28:07

Please try this patch.  Instead of using a Goto to break out of your loop, use ExitWhile.

By: Leif Madsen (lmadsen) 2006-04-20 21:57:22

Can someone give a good use of this? Is this a good way to break a While() loop if a certain OTHER condition you want to check for is met? If so, then it might make sense to have ExitWhile() just exit if no arguments are given.

Maybe allowing ExitWhile() to contain a condition as an argument to decide whether to exit or not?

ExitWhile($[${MY_CONDITION} = TRUE])

If ${MY_CONDITION} is TRUE, then the While() loop would exit

Is there a way of cleanly doing this without really requiring any modification, or am I misunderstanding the use of this application?

By: Leif Madsen (lmadsen) 2006-04-20 22:03:26

Seems that I can do this:

exten => s,n,ExecIf($[${MY_CONDITION} = TRUE],ExitWhile)

However I still think accepting a condition to the ExitWhile() is still an idea that could be discussed -- at least there's a work around :)

BTW: This patches cleanly against the app_while.c in 1.2 release as of today and works for me!

By: Tilghman Lesher (tilghman) 2006-04-21 08:54:27

I was also considering implementing ContinueWhile, which would branch immediately back to the While condition and reevaluate, rather than to continue on until it finds EndWhile.

By: Tilghman Lesher (tilghman) 2006-04-21 08:56:12

There's been some concern over whether we ought to have *If commands for many of the apps that already exist.  The decision was made that if you need *If functionality, you should use ExecIf, since that's all that that app does.

By: Tilghman Lesher (tilghman) 2006-04-21 18:27:01

And ContinueWhile.

By: Matt O'Gorman (mogorman) 2006-04-26 13:49:57

Committed revision 22573.

By: Matt O'Gorman (mogorman) 2006-04-26 13:50:22

continue and exitwhile were committed into trunk. I hope this helps george.