GoFiler Legato Script Reference
Legato v 1.5b Application v 5.24b
|
Table of Contents | < < Previous | Next >> |
Chapter Four — Flow Control (continued)
The ‘for’ loop is defined by the for keyword. A boolean expression is contained within the ‘for’ loop syntax, and the code is executed repeatedly until that condition becomes false. ‘for’ loops feature explicit counting, where the counting variable is assigned and incremented in the loop statement itself. This is appropriate in situations where the number of iterations is clearly defined, such as moving through an array.
The for statement uses the following formal syntax:
for (init-expression; cond-expression; loop-expression) {
statement(s)
}
A for loop consists of three parts: initialization, condition, and loop-expression. The following example illustrates a ‘for’ loop:
int i;
for (i = 0; i < 10; i++) {
MessageBox("This is the number %d", i);
}
i = 0 represents the init-expression, i < 10 represents the cond-expression, and i++ is the loop-expression. The start point of the loop and its end point are clearly defined in the loop statement itself, as well as the manner in which the counting variable is incremented. The condition is tested at the top of loop; it should be noted that the loop might never be entered if the boolean condition does not result in TRUE at least once.
The init-expression and loop-expression may contain multiple items separated by commas. For example:
int i, j;
for (i = 0, j = 10; i < 10; i++, j--) {
MessageBox("This is the number %d and %d", i, j);
}
The expressions can contain essentially anything. The cond-expression must resolve into a boolean.
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.
Table of Contents | < < Previous | Next >> |
© 2012-2024 Novaworks, LLC. All rights reserved worldwide. Unauthorized use, duplication or transmission prohibited by law. Portions of the software are protected by US Patents 10,095,672, 10,706,221 and 11,210,456. GoFiler™ and Legato™ are trademarks of Novaworks, LLC. EDGAR® is a federally registered trademark of the U.S. Securities and Exchange Commission. Novaworks is not affiliated with or approved by the U.S. Securities and Exchange Commission. All other trademarks are property of their respective owners. Use of the features specified in this language are subject to terms, conditions and limitations of the Software License Agreement.