Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.4j

Application v 5.22b

  

 

Chapter FourFlow Control (continued)

4.2 Statements and Blocks

4.2.1 Overview

Program sections are delineated at various levels. At the highest level is the entire program or script. The next level would be functions or subroutines. Within those are groups or blocks of instructions. A block could be, for example, if a condition is true, then execute the following instructions. Finally, there is the statement which contains the instructions.

The following reviews these levels from the lowest to the highest level.

4.2.2 The Statement

Within Legato, i = 0 or MessageBox("Hello world!") become statements when followed by a semicolon. For example:

i = 16;

f = 3.14 * c;

s = "My String";

Like C/C++, Java, and many other languages, the semicolon is a statement terminator. This character tells the interpreter to execute the information prior to the semicolon at once. Generally, as shown above, statements will have a left and right side. The left side, when present, must specify a variable. Presumably there is an assignment operator between the left and right sides. The right side can contain something as simple as a literal number to as complex as a series of functions and mathematical operations.

Conventionally, left and right side are considered l-values and r-values. Terms on the right side can be any number of types of data from variables to literals. Other the other hand, when present, the l-value may only be a variable.

A statement can be a simple function call:

MessageBox('X', "Please Enter a Value.");

CreateFolder(path);

In such a case, the l-value is thrown away, even if a return value is provided by the function. 

4.2.3 Blocks

A block is a section of code which is grouped together. Often a section of code may have a logical basis connecting the statements within it, such as code that should be executed in the event of an error. Blocks allow a group of statements to be treated as if it was a single statement. Legato keywords, such as if, else, for, and while, are often linked with a block of code. A block is delineated by curly braces (“{” to begin a block and “}” to end it). For example:

int main {

int i = 0;

while (i < 10) {

if (i % 2 == 0) {

MessageBox("%d mod 2 == 0", i);

MessageBox("%d is an even number less than 10", i);

} else {

MessageBox("%d mod 2 != 0", i);

MessageBox("%d is an odd number less than 10", i);

}

i++;

}

return 0;

}

The above code contains numerous blocks, some of which are nested. There is a while loop that iterates through integers from 0 to 10, and within that block, there is a nested if/else block that conditionally executes code dependent on the value of i % 2.

Blocks directly control the flow of script execution through the keywords connected to them.

4.2.4 Functions

A function can be considered as a sequence of programming statements that perform a task. Tasks can be as simple as converting one temperature scale to another (as seen in Section 2.1 Some Simple Programs) or as complex as handling messages for a dialog or loading a file into an edit window.

For more information on functions, see Section 4.10 Script Functions.

4.2.5 Programs

Program execution begins at the program entry point, which may be implicitly or explicitly defined (see section 4.3 for more information), and continues until script completion. In a simplistic sense, this could be the last line of code for the script or a final return statement. However, this could also occur along other control paths throughout the script.

Scripts can also call other programs or scripts, transferring execution to the called program much like calling a function. Execution returns to the script once the called program returns.