• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

[Lua 5.2] Goto statement.

tarjei

Necronian Engineer
Joined
May 25, 2008
Messages
505
Reaction score
126
Location
Poland
Hello! Recently I started playing with new lua version, and I came across usefull things - goto statements.
If you are familiar with assembler labels they are familiar, yet in lua it is much more restricted.
However you can make a nice structures with it, that simply were not avaible without this.

Take a look at this example:
Code:
for i = 0,  10 do
    ::redo:: --defining a label
   
    if i%2==0 then
        print("Continue "..i)
      goto continue--We skip a code to continue label (at the end of the loop)
    end
    print("Regular")
   
    ::continue::
end

To try it out, you would need to compile independent lua 5.2 interpreter, or make few changes to use it inside your engine, cheers :)
 
Terribad! XD
Actually was good to show about this new feature of lua 5.2, but for programing stuff, there is some methods that cand make hard to "read" your program.
One is global variables
Two is goto statment...
 
Interesting, but from what I heard programmers hate this feathure. I didn't found any use for it either.
I always avoid using goto in any language, because there are plenty of ways to write code better
 
Well I found it useful at least for making simple continuation of loop, if I want some part of code to be skipped under some circumstances: P
 
Back
Top