2.3.1.2.2 Using Semicolons in LabTalk

Separate Statements with a Semicolon

Like the C programming language, LabTalk uses semicolons to separate statements. In general, every statement should end with a semicolon. However, the following rules clarify semicolon usage:

  • Do not use a semicolon when executing a single statement script in the Script window.
    • An example of the proper syntax is: type "hello" (ENTER).
    • The interpreter automatically places a semicolon after the statement to indicate that it has been executed.
  • Statements ending with { } block can skip the semicolon.
  • The last statement in a { } block can also skip the semicolon.

In the following example, please note the differences between the three type command:

if (m>2) {type "hello";} else {type "goodbye"}
type "the end";

The above can also be written as:

if (m>2) {type "hello"} else {type "goodbye"}
type "the end";

or

if (m>2) {type "hello"} else {type "goodbye"};
type "the end";

Leading Semicolon for Delayed Execution

You can place a ';' in front of a script to delay its execution. This is often needed when you need to run a script inside a button that will delete the button itself, like to issue window closing or new project commands. For example, placing the following script inside a button will possibly lead to a crash

// button to close this window
type "closing this window";
win -cn %H;

To fix this, the script should be written as

// button to close this window
type "closing this window";
;win -cn %H;

The leading ';' will place all scripts following it to be delayed when executed. Sometimes you may want a specific group of statements delayed, then you can put them inside {script} with a leading ';', for example:

// button to close this window
type "closing this window";
;{type "from delayed execution";win -cn %H;}
type "actual window closing code will be executed after this";

See Also: LabTalk System Variable @LT