MetaScript statements consist of keywords used with the appropriate syntax. A single statement may span multiple lines. Multiple statements may occur on a single line if each statement is separated by a semicolon.
Syntax conventions: All keywords in syntax statements are in bold. Words in italics represent user-defined names or statements. Any portions enclosed in square brackets, [ ], are optional. {statements} indicates a block of statements, which can consist of a single statement or multiple statements delimited by a curly braces { }.
The following table lists statements available in MetaScript.
Statement | Description |
---|---|
break | Terminates the current while or for loop and transfers program control to the statement following the terminated loop. |
comment | Notations by the author to explain what a script does. Comments are ignored by the interpreter. |
continue | Terminates execution of the block of statements in a while or for loop, and continues execution of the loop with the next iteration. |
do...while | Executes the specified statements until the test condition evaluates to false. Statements execute at least once. |
for | Creates a loop that consists of three optional expressions, enclosed in parentheses and separated by semicolons, followed by a block of statements executed in the loop. |
for...in | Iterates a specified variable over all the properties of an object. For each distinct property, MetaScript executes the specified statements. |
function | Declares a function with the specified parameters. Acceptable parameters include strings, numbers, and objects. |
if...else | Executes a set of statements if a specified condition is true. If the condition is false, another set of statements can be executed. |
label | Provides an identifier that can be used with break or continue to indicate where the program should continue execution. |
return | Specifies the value to be returned by a function. |
switch | Allows a program to evaluate an expression and attempt to match the expression's value to a case label. |
throw | Throws a user-defined exception. |
try...catch | Marks a block of statements to try, and specifies a response should an exception be thrown. |
var | Declares a variable, optionally initializing it to a value. |
while | Creates a loop that evaluates an expression, and if it is true, executes a block of statements. The loop then repeats, as long as the specified condition is true. |
with | Establishes the default object for a set of statements. |