jump label
A jump is like a
goto in other languages. Jumps can be used to alter normal
flow control. When a jump occurs,
script execution immediately moves to the next
statement after the corresponding
label definition, skipping intervening
code and breaking out of any
loops.
Labels are defined by an arbitrary
name, prefixed with an
@ (ampersand)
character.
Example:
list gList;
integer scanForThingys(){
integer i;
integer len = llGetListLength(gList);
for (i = 0; i < len; i++){
if ( isThingy( llList2String(gList, i) ) )
jump getOut;
}
i = -1;
@getOut; // when the jump is executed this script leaves the FOR loop and continues from here
return i;
}
Note: a jump only works within the current
scope, a
global function, or an
event handler. Jumps don't work
between global functions or event handlers.
Most coders recommend avoiding jumps where possible and you'll find that they are rarely necessary in well-structured code.
LSL lacks a "
break" feature that is standard in most languages for leaving a loop early so this is one case where a jump can be useful. Careful coders will avoid jumping backwards or too far forwards in their code.
For more on the subject see:
GoTo Statement Considered Harmful.
Flow Control