2.3.1.2.2 Using Semicolons in LabTalkUsing-Semicolons-in-LT
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, with the following exceptions:
- Single statement script in the Script window.
-
type "hello" . With cursor anywhere on the same line, press ENTER will execute it. ; will be auto added at the end to indicate the execution
- If there is ; e.g.
type "hello"; , The cursor must be put before ; to execute it
- The last statement inside a { } block
if (m>2) {type "hello"; type "goodbye"} // no ; needed right before }
//if (m>2) {type "hello";} else {type "goodbye";} //no ; needed right after }
Leading Semicolon for Delayed ExecutionDelayed 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
|