Recursive subroutines

Dear all,
I have created subroutine that called itself, but the result was displayed incorrect on output console
So, May I create a subroutine that can call itself in dialplan?
Contents of extensions.conf file were:


[subRecursiveRoutine]
exten => s,1,Set(LOCAL(Count)=${ARG1})
exten => s,2,Set(LOCAL(Counter)=1)
exten => s,3,While($[${Counter} <= ${Count}])
exten => s,4,GotoIf($[${Count} = 2]?:6)
exten => s,5,GoSub(subRecursiveRoutine,s,1(4))
exten => s,6,Verbose(2,Counter=${Counter},Count=${Count})
exten => s,7,Set(Counter=$[${Counter} + 1])
exten => s,8,EndWhile
exten => s,9,Return

[test]
exten => 100,1,GoSub(subRecursiveRoutine,s,1(2))

I have used SIP phone to dial to 100 extension, I have seen on output console only 5 verbose messages. That’s incorrect

Please help me!

This is the wrong forum for support questions.

You say you get the wrong output, but you don’t provide that output.

I would think recursive calling would be a rather low priority.

Dear david55,
Because it is the first time i have post question to forum, so i don’t know correct place to post. Can you tell me where to post my problem? I have read the guide to post a question, but i don’t have know where to go.
I will post the output to correct forum
Thanks.

Looks like it has been moved.

Questions requiring, and appropriate for, unpaid help in designing a system, installing, configuring and debugging it, go in a forum with Support in the name.

If you are not using a GUI, they go in Asterisk Support.

If you are using a GUI, as part of AsteriskNow, and the question relates to Digium extensions to the GUI, or the way the GUI is packaged into AsteriskNow, they go in AsteriskNow Support.

If they relate to other aspects of a GUI, they should be addressed to a board for that GUI, not one of the forums here.

Questions requiring more time than is reasonable for free consultancy (e.g. requests to design a system, provide worked examples, or step by step instructions) go in Jobs. If the application is an outbound call centre, the threshold for this is much lower than for other applications.

Questions likely to involve changes to the source code, and requests for new features, go to the developer mailing list.

Crashes and deadlocks in currently supported versions go to the issue tracker, but you must be able to provide backtraces, etc., in the required forms. If there is any possibility that you may be seeing intended behaviour, Asterisk Support may be an appropriate place to pre-qualify the report, but you could also use the developer mailing list.

If you want to comment on the philosophy behind Asterisk, its future, etc., then Asterisk General is likely to be appropriate.

Thanks david55 for your explaination,
The verbose output from console for my dialplan code were as following:
The bold red texts were my comments

Executing [100@MakeCall:1] GoSub(“SIP/300-00000004”, “subCheck,s,1(2)”) [color=#FF0000] -------> Go to outer Sub[/color]
– Executing [s@subCheck:1] Set(“SIP/300-00000004”, “LOCAL(Count)=2”) in new stack
– Executing [s@subCheck:2] Set(“SIP/300-00000004”, “LOCAL(Counter)=1”) in new stack
– Executing [s@subCheck:3] While(“SIP/300-00000004”, “1”) in new stack
– Executing [s@subCheck:4] GotoIf(“SIP/300-00000004”, “1?:6”) in new stack
– Executing [s@subCheck:5] Gosub(“SIP/300-00000004”, “subCheck,s,1(4)”) in new stack [color=#FF0000] -------> Go to inner Sub[/color]
– Executing [s@subCheck:1] Set(“SIP/300-00000004”, “LOCAL(Count)=4”) in new stack
– Executing [s@subCheck:2] Set(“SIP/300-00000004”, “LOCAL(Counter)=1”) in new stack
– Executing [s@subCheck:3] While(“SIP/300-00000004”, “1”) in new stack
– Executing [s@subCheck:4] GotoIf(“SIP/300-00000004”, “0?:6”) in new stack
– Goto (subCheck,s,6)
– Executing [s@subCheck:6] Verbose(“SIP/300-00000004”, “2,Counter=1,Count=4”) in new stack
== Counter=1,Count=4 [color=#FF0000] -------> Verbose 1th from inner Sub[/color]
– Executing [s@subCheck:7] Set(“SIP/300-00000004”, “Counter=2”) in new stack
– Executing [s@subCheck:8] EndWhile(“SIP/300-00000004”, “”) in new stack
– Executing [s@subCheck:3] While(“SIP/300-00000004”, “1”) in new stack
– Executing [s@subCheck:4] GotoIf(“SIP/300-00000004”, “0?:6”) in new stack
– Goto (subCheck,s,6)
– Executing [s@subCheck:6] Verbose(“SIP/300-00000004”, “2,Counter=2,Count=4”) in new stack
== Counter=2,Count=4 [color=#FF0000] -------> Verbose 2th from inner Sub[/color]
– Executing [s@subCheck:7] Set(“SIP/300-00000004”, “Counter=3”) in new stack
– Executing [s@subCheck:8] EndWhile(“SIP/300-00000004”, “”) in new stack
– Executing [s@subCheck:3] While(“SIP/300-00000004”, “1”) in new stack
– Executing [s@subCheck:4] GotoIf(“SIP/300-00000004”, “0?:6”) in new stack
– Goto (subCheck,s,6)
– Executing [s@subCheck:6] Verbose(“SIP/300-00000004”, “2,Counter=3,Count=4”) in new stack
== Counter=3,Count=4 [color=#FF0000] -------> Verbose 3th from inner Sub[/color]
– Executing [s@subCheck:7] Set(“SIP/300-00000004”, “Counter=4”) in new stack
– Executing [s@subCheck:8] EndWhile(“SIP/300-00000004”, “”) in new stack
– Executing [s@subCheck:3] While(“SIP/300-00000004”, “1”) in new stack
– Executing [s@subCheck:4] GotoIf(“SIP/300-00000004”, “0?:6”) in new stack
– Goto (subCheck,s,6)
– Executing [s@subCheck:6] Verbose(“SIP/300-00000004”, “2,Counter=4,Count=4”) in new stack
== Counter=4,Count=4 [color=#FF0000] -------> Verbose 4th from inner Sub[/color]
– Executing [s@subCheck:7] Set(“SIP/300-00000004”, “Counter=5”) in new stack
– Executing [s@subCheck:8] EndWhile(“SIP/300-00000004”, “”) in new stack
– Executing [s@subCheck:3] While(“SIP/300-00000004”, “0”) in new stack
– Executing [s@subCheck:9] Return(“SIP/300-00000004”, “”) in new stack [color=#FF0000] -------> Return from inner Sub[/color]
– Executing [s@subCheck:6] Verbose(“SIP/300-00000004”, “2,Counter=1,Count=2”) in new stack
== Counter=1,Count=2 [color=#FF0000] -------> Verbose 1th from outer Sub[/color]
– Executing [s@subCheck:7] Set(“SIP/300-00000004”, “Counter=2”) in new stack
– Executing [s@subCheck:8] EndWhile(“SIP/300-00000004”, “”) in new stack
– Executing [s@subCheck:9] Return(“SIP/300-00000004”, “”) in new stack [color=#FF0000] -------> I think the problem at here, why is the While the command can’t executed?[/color]
– Executing [100@MakeCall:2] Hangup(“SIP/300-00000004”, “”)

Thanks in advance

I think the problem is that your gosub is calling gosub so when it returns it returns to what called it, you might want to look at a gosub then use gotoif for the counter and see what that does.

Dear Ianplain,
According to ouput from the previous submit, The gosub have return where and what was called it, it was at priority 5, and the command at priority 6 was executed correctly, it have printed values of Counter=1, Count=2, next the command at priority 7 was executed correctly, so value of Counter=2. When the command at priority 8 (EndWhile) was executed, it should be go to While command at priority 3, but that haven’t happened. It did go to the Return command!!!
Do you have any ideas?
Thanks

Hi

There are better ways of doing this but its looks correct endwhile then return which it does, add a 2nd priority to 100 and see the return value.