Skip to content
lsl.devlsl.devLSL Dev
LSL Conditional: {{LSL_Conditional |statement=for |statement_header |statement_desc=Only the condition is required. The initializer, increment, and loop body are optional and can be left empty. |statement_end=loop |statement_end_desc=Can be either a single statement, a block statement, or a null statement. |p1_name=initializer|p1_desc=Executed once just before checking '''condition'''. |p2_name=condition|p2_desc=If this executes as true then '''loop''' is executed. |p3_name=increment|p3_desc=Executed after '''loop''', then '''condition''' is checked again. |constants |spec |caveats |examples= The following is the most common way a for-loop is written, with each part properly specified. The loop will run or "iterate" 10 times, from 0 to 9. It will execute two statements each iteration.
integer a = 0;
integer b = 10;
for (a = 0; a < b; ++a)
{
    llOwnerSay( (string)a ); // first statement
    llOwnerSay( (string)b ); // second statement
}
The following is less common, where the curly braces are left out. This can be used when only one statement needs to be executed during the loop.
integer a = 0;
integer b = 10;
for (a = 0; a < b; ++a)
    llOwnerSay( (string)a ); // single statement
Although the following is technically possible, it's not recommended because it's hard to read and maintain. The initialization is left out because the variable <code>a</code> already has the value zero. The loop body is left out because the increment statement includes a function call which does everything that's needed.
integer a = 0;
integer b = 10;
for ( ; a < b; llOwnerSay((string)(++a)) )
    ; // empty statement (could be at the end of the previous line)
|helpers |also_header |also_functions |also_tests |also_articles |also_footer |notes= A for-loop can also be written as a [[While]]-loop.
initializer;
while(condition)
{
    loop;
    increment;
}
|mode |deprecated |cat1=Flow Control/Loop |cat2=Conditional |cat3 |cat4 }}
Original wiki source

Some wiki templates and tables need their original context. View this article on the Second Life Wiki. Technical wording and examples are retained from the source; historical guidance may differ from current behavior.

From the Second Life Wiki

Community documentation adapted from For, by Linden Research, Inc. and contributing residents.View contributors and history.

Imported wiki revision:

  • For (revision 1213958, )

Licensed under CC BY-SA 3.0. Last wiki edit: .Formatting and links have been adapted for this site; API metadata follows the LSL definitions.