Don't click here unless you want to be banned.

LSL Wiki : jump

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl338.us.archive.org
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.

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;
}

Example: This example shows how the jump label 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;
@Loop;
if(i > 1000) jump Done;
else
{
    llSetText("Jump\n"+(string)i,<1,1,1>,1);
    i++;
}
jump Loop;
@Done;
llSay(0,"Broke!");
-KageshenKirax
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.


image courtesy of http://xkcd.com/

Flow Control Jasa SEO Jasa SEO Murah Sepatu Online Toko Sepatu Online Sepatu Sepatu Murah Sepatu Safety Sepatu Futsal Cheapes Hostgator Coupon Link Booking Televisori offerte Notebook Offerte Berita Terkini Internet Marketer Muda Internet Marketer Indonesia Portatile Apple RDAnet Lorks Karikatur Bisnis Modal Kecil Bisnis UKM Berita Terbaru Iklan Baris Jasa SEO Jasa SEO Murah SEO Indonesia Konsultan SEO SEO Belajar SEO Kursus SEO Kursus SEO Murah Jam Tangan Casio Jam Tangan Casio Jam Tangan Murah Jam Tangan Grosir Baju Terbaru Grosir Baju Baju Terbaru Grosir Baju Murah Bisnis Online Belajar SEO Kerupuk Kerupuk kulit Social Bookmark Dofollow Social Bookmark Kumpulan Puisi Kirim Puisi bola hantu Penumbuh Rambut Penumbuh Rambut timbangan WBC Wonogiri Jasa SEO Murah Jasa SEO Jam Tangan Murah
Comments [Hide comments/form]
having two jumps go to one target doesn't seem to work. so if you want to jump to a target twice, make two targets where you want to jump to.
-- RickardRoentgen (2004-12-30 01:45:17)
"They're essential for jumping outof loops where a return doesn't make sense."

This is definitely important, considering we don't seem to get a "break;" statement. I can see myself using jump for this. Mindlessly repeating the mantra "Go To Statement Considered Harmful" is not always the best idea ;)
-- LexNeva (2005-01-26 13:51:18)
A follow-up on the Comment by RickardRoentgen above:
having two jumps inside a for loop that jump to the same target results in
the for loop not being exited at all. I consider this a serious bug.
-- DamienRutherford (2005-09-11 13:56:12)
I don't see any bugs with this function, for exampe.
//infinite loop
@a;
jump a;
Takes up less memory then while(1) or do...while(1) or for(;1;)
Sure using jump usualy signals bad coding but it still is useful.
-- BlindWanderer (2005-09-11 17:10:09)
Better way to do the example mentioned in the main article:
list gList;
integer scanForThingys() {
    integer i;
    integer len = llGetListLength(gList);
    for (i = 0; i < len; ++i) {
        if (isThingy(llList2String(gList, i)))
            return i;
    }
    return -1;
}
No need for the jump in this scenerio.
-- ChristopherOmega (2006-02-12 11:30:16)
Just wondering....isn't '&' an ampersand?
If so, the '@' has another, more correct name... :)
-- GottaLoveForcedCaps (2006-10-22 13:33:06)
Just checked. The technical name for it is "asperand". But why not make everyone's life easier and just call it an "at sign", if it needs to be called anything?
-- GottaLoveForcedCaps (2006-10-22 13:38:48)
In most cases a jump is not necessary.

The example could be rewritten without a jump.
{
integer len= ....;
integer i;
integer flag = FALSE;
for (i = 0; !flag && i < len; ++i)
{
    if ( ... )
        flag = TRUE;
}

// here some other code that needs to be executed independend of the value of flag
// so the return in the loop won't work..

if (flag)
    return i;

return -1;
}
-- HeusDens (2007-08-12 21:51:36)
Attach a comment to this page: