Name: do

Type: command

Syntax: do <statementList> 

Syntax: do <statementList> in <caller> 

Syntax: do <statementList> as a <lternateLanguageName> 

Summary: <execute|Executes> a list of <statement|statements>.

Introduced: 1.0

OS: mac,windows,linux,ios,android

Platforms: desktop,server,web,mobile

Example:
do "go next card"

Example:
do "put"  x  "into tNumberOfRecords"  x -- might become "put 3 into tNumberOfRecords"

Example:
do "select"  line 3 of field "Objects"

Example:
do field "Statements" as AppleScript

Parameters:
statementList: A LiveCode statement, a container with one or more statements, or a string that evaluates to a statement.
caller: Has the effect of executing the statementList in the context of the handler.
lternateLanguageName: 
alternateLanguageName: On Mac OS and OS X systems, the alternateLanguageName is a script language (such as AppleScript) supported under the Open Scripting Architecture. On Windows systems, the alternateLanguageName is an "active scripting" language (such as VBScript) supported by the Windows Scripting Host. The available languages are returned by the alternateLanguages function. If you specify an alternateLanguageName, the statementList must be written in the specified language.

The result: On Mac OS X systems, if you use the do as a <lternateLanguageName> form, any result returned by the script language is placed in the <result>. On Windows systems, the <result> function will return the value of the global variable called "result" in the script that was executed (or empty if no such variable was defined). For example the following code will produce a dialog box containing "2":. answer the result. If you attempt to specify an <alternateLanguageName> on a <Unix> <system>, the <do> <command> is not executed, and the <result> is set to "alternate language not found". Any scripts on Windows which contain references to WScript will fail to run as WScript objects do not exist in the LiveCode Environment.  Return values should therefore be placed within the global <result> variable instead of using WScript.Echo.

Description:
Use the <do> command to execute statements in a container, or to execute a statement that consists partly of a literal string and partly of a container or the return value from a function.

Using the <do> <command> is slower than directly <execute|executing> the <command|commands>, because each <statement> must be <compile|compiled> every time the <do> <command> is executed.

do "result = 1 + 1" as "vbscript"

>*Important:* If using the do as <alternateLanguageName> form, any paths used in the <statementList> must be in the native format of the current system. In particular this means that paths must be converted to Windows native format before use on Windows machines. In most cases this can be done by replacing slash with backslash in the path.

To see how to create a numbered set of variables see the dictionary entry for the <local command>.

The ability to specify an <alternateLanguageName> on Windows systems was added in LiveCode 2.9.

Changes:
The <alternateLanguageName> option was introduced in version 1.1. In previous versions, it was not possible to include AppleScript or other <Open Scripting Architecture (OSA)|OSA> languages in a <Revolution|LiveCode> <handler>.

References: message box (keyword), as (keyword), debugDo (command), breakpoint (command), local (command), call (command), local command (command), result (function), alternateLanguages (function), system (glossary), Revolution (glossary), handler (glossary), execute (glossary), statement (glossary), Unix (glossary), compile (glossary), command (glossary), Open Scripting Architecture (OSA) (glossary)
