Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.4j

Application v 5.22b

  

 

Chapter FourFlow Control (continued)

4.4 Loops

4.4.1 Overview

Loops are extremely useful constructs for processing series of data in roughly the same way. For example, loops can be used to reorder items within an array or to iterate through a list and search for a particular entry. There are multiple types of loops which are described in the subsequent sections, and some loop structures lend themselves to different situations.

A loop contains a basic structure: iteration through a series of statements so long as a conditional expression evaluates to TRUE. The expression is tested for each iteration of the loop.

4.4.2 Exiting Loops

A loop will exit and execution will fall into the code below when:

1. The condition of the loop is satisfied (the expression resolves to FALSE)

2. A break statement is encountered.

3. A return statement is encountered.

4. An exit statement is encountered.

It is the programmer’s responsibility to ensure a loop reaches a condition where it will exit. If a script is stuck in a infinite loop, the application may hang and become unresponsive.

4.4.3 The ‘break’ Keyword

The break keyword exits a loop immediately. Execution resumes at the end of the brace belonging to the loop. This statement is useful to ending loop execution upon a certain condition, such as an error.

4.4.4 The ‘continue’ Keyword

The continue keyword skips the remainder of the loop block statements and forces execution to resume from the first line following the initial for, while, or do loop statement. This statement is useful to skip processing the remainder of code in the loop upon a certain condition, such as passing a particular test case.