For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Log inSign up
Support
ReferenceGuides
ReferenceGuides
    • Quickstart
  • Basics
    • Control program flow
    • Deploy SWML from web servers
    • Handle incoming calls from code
    • Send simple HTTP requests
  • Recipes
    • Call whisper
    • Forwarding calls
    • Making and receiving phone calls
    • Recording calls
    • Setting up voicemail
    • Simple IVR
  • SWAIG Functions
    • Overview
    • Enable functions dynamically
    • Execute SWML from a function
    • Handle SWAIG function calls inline
    • Store data outside LLM context
    • Switch AI context mid-call
LogoLogoSignalWire Docs
Log inSign up
Support
On this page
  • goto
  • execute
  • transfer
  • Conclusion
Basics

Control program flow

How are the methods goto, execute and transfer different?
|View as Markdown|Open in Claude|
Was this page helpful?
Edit this page
Previous

Deploy SWML from web servers

Serve SWML scripts from web servers and RELAY applications
Next
Built with

SWML offers a lot of flexibility in how you control program flow with its control methods. Of these, goto, execute, and transfer allow you to unconditionally control program flow.

goto

The goto method is designed to allow you to jump to particular labels within a section. Use this method to simulate more complex loops like while and for loops.

You cannot jump to sections using goto. Use execute described further below to jump sections.

1version: 1.0.0
2sections:
3 main:
4 - play:
5 url: 'say:Entering infinite loop'
6 - label: loop
7 - play:
8 url: 'say:Looping ...'
9 - goto:
10 label: loop

execute

The execute method allows you to invoke a subsection as a function. You can pass parameters to the function and receive a return value.

1version: 1.0.0
2sections:
3 main:
4 - play:
5 url: 'say:Transferring you to another section'
6 - execute:
7 dest: subsection
8 - play:
9 url: 'say: ${return_value}'
10 subsection:
11 - play:
12 url: 'say:inside a subsection'
13 - return: back!

Output transcript:

"Transferring you to another section"
"inside a subsection"
"back!"

Or in a more complex example:

1version: 1.0.0
2sections:
3 main:
4 - play:
5 url: 'say:Transferring you to another section'
6 - execute:
7 dest: subsection
8 params:
9 a: 1
10 b: 2
11 - play:
12 url: 'say: ${return_value}'
13 subsection:
14 - return: '${params.a+params.b}'

transfer

1version: 1.0.0
2sections:
3 main:
4 - play:
5 url: 'say:Transferring you to another section'
6 - transfer:
7 dest: subsection
8 - play:
9 url: 'say:Back!'
10 subsection:
11 - play:
12 url: 'say:inside a subsection'

Output transcript:

"Transferring you to another section"
"inside a subsection"

Notice how we aren’t going back to the calling section at all.

Conclusion

gotoexecutetransfer
UseJump between labels within a sectionInvoke a subsection with params, then returnInvoke a subsection with params
Scopewithin a sectionFrom one section to another, or to another SWML fileFrom one section to another, or to another SWML file