Labels

Table of Contents

Syntax and Usage

A label identifies a line of code, and can be used as a Goto target or to specify a loop to break out of or continue. A label consist of a name followed by a colon:

this_is_a_label:

Aside from whitespace and comments, no other code can be written on the same line as a label.

Names: Label names are not case sensitive (for ASCII letters), and may consist of letters, numbers, underscore and non-ASCII characters. For example: MyListView, Menu_File_Open, and outer_loop.

Scope: Each function has its own list of local labels. Inside a function, only that function's labels are visible/accessible to the script.

Target: The target of a label is the next line of executable code. Executable code includes functions, assignments, expressions and blocks, but not directives, labels, hotkeys or hotstrings. In the following example, run_notepad_1 and run_notepad_2 both point at the Run line:

run_notepad_1:
run_notepad_2:
    Run "notepad"
    return

Execution: Like directives, labels have no effect when reached during normal execution.

Look-alikes

Hotkey and hotstring definitions look similar to labels, but are not labels.

Hotkeys consist of a hotkey followed by double-colon.

^a::

Hotstrings consist of a colon, zero or more options, another colon, an abbreviation and double-colon.

:*:btw::

Dynamic Labels

In some cases a variable can be used in place of a label name. In such cases, the name stored in the variable is used to locate the target label. However, performance is slightly reduced because the target label must be "looked up" each time rather than only once when the script is first loaded.

Named Loops

A label can also be used to identify a loop for the Continue and Break statements. This allows the script to easily continue or break out of any number of nested loops.

Functions, IsLabel, Goto, Break, Continue