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 @ (at sign) character.


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;

Example: This example shows how the jumplabel can be used as a loop. I have done some test and this is the fastes loop out of the do-while, while, and the for-loop.

integer i;
if(i > 1000) jump Done;
jump Loop;


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.

Note: Please see the comments, you can only have a single jump statement going to a label.


Credit to: Lslwiki.net (not working) with changes made for brevity and clarity.