Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.4j

Application v 5.22b

  

 

Chapter FourFlow Control (continued)

4.5 The ‘while’ Loop

4.5.1 Overview

The ‘while’ loop is defined by the while keyword. The code is executed repeatedly until the boolean condition becomes false. ‘While’ loops differ from ‘do’ loops in that the condition is tested before the loop executes.

4.5.2 Syntax and Structure

The while statement uses the following formal syntax:

while (expression)

   statement(s)

 

The following example illustrates a while loop:

int i;

i = 0;

while (i < 10) {

  MessageBox("This is the number %d", i);

  i++;

  }

 

Note that in ‘while’ and ‘do’ loops the counting variable is not incremented automatically as part of the loop structure. It is the programmer’s responsibility to create looping structures and conditional expressions that result in a finite loop. Infinite loops may cause the application to behave unexpectedly or even hang so they must be used with care. The break and continue keywords can be used to control loop execution. In addition, the return or exit statements can end loop iteration.