Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.5b

Application v 5.24b

  

 

Chapter FourFlow Control (continued)

4.8 ‘if’, ‘elseif’ and ‘else’ Statements

4.8.1 The If Condition

The if statement processes a single expression and then acts depending the on boolean result of that process. The expression can be simple or extremely complex, but in the end, must resolve to logical FALSE or TRUE. For example:

if (a == b) {

...

}

if (response != "YES") {

...

}

if ((a == b) && (b == c)) {

...

}

 

If the result is nonzero (TRUE), the statement or block of statements following the if statement will be executed. If the result is zero (FALSE), the statement or block of statements is skipped. In addition, an else conditional can be added to execute a statement or block of statements if the boolean expression results in a FALSE condition.

The elseif statement allows a series of conditions to be in the form of a cascade:

if (response == "YES") {

...

}

elseif (response == "NO") {

...

}

elseif (response == "CANCEL") {

...

}

else {

...

}

Unlike the first example, this comprises an interconnected set of conditions. If the response is false, the next elseif condition is tested and so on. An optional end else can be added for the end catch all.

4.8.2 Syntax and Structure

The if, elseif and else statements use the following formal syntax:

if (expression) {

statement(s)

}

[elseif (expression) {]

[statement(s)]

}

[else]

[statement(s)]

}

 

Zero or more elseif statements can be added, but the elseif must be associated with a preceding if block. The else statement is optional and when omitted, program execution will continue after the block if the expression is not true. The elseif and else statements must immediate precede the related conditional block.