Scope start if while repeat for - jpbubble/NIL-isn-t-Lua GitHub Wiki

NIL follows most of the rules Lua has set up for this, although the rules are not ENTIRELY the same, so some caution is in order.

  • Where you start the 'if'/'while'/'repeat' lines that's the same as in Lua, although it may (but then again, nothing may) not be in the same line as a '#' directive or a variable/function declare line.
  • The expressions following 'if', 'elseif', 'while' and 'until' MUST be on the same line as the specific keyword.
  • The keywords 'do' and 'then' are only required if the following instructions are on the same line. If the first command of the following scope is on the next line 'do' and 'then' may be omitted.
  • Alternatively a 'repeat' scope may be ended with the keyword 'forever' in order to create an infinite loop.
  • You can also set "#repeatmayend", and if you do so ending a 'repeat' scope with an 'end' will also create an infinite loop.
    • NOTE: This works per chunk, and not globally over the entire state
    • NOTE: Since infinite loops should be avoided unless you are sure you want one, I've turned this off by default to make sure you don't accidentally create an infinite loop simply by using 'end' in stead of 'until'.
    • NOTE: Since 'forever' already needs to be typed explicitly, I'm not sure if using 'end' is a good idea for this at all, but hey, you can do it, right?

A few examples

// NOT acceptable in NIL (while it is in Lua)
if
    a == 1
then
    print("hi")
end


// Accepted in both NIL and Lua
if a==1 then
   print("hi")
end

// Accepted in NIL, but NOT in Lua
if a==1 
   print("hi")
end

// Neither Lua nor NIL will accept this:
if a==1 print("hi") end

I guess it's not that hard to understand, but still it had to be noted ;)

⚠️ **GitHub.com Fallback** ⚠️