This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
CRUGG's profile picture

Error about a missing 'end'

Started by CRUGG, 28 March 2018 - 01:35 PM
CRUGG #1
Posted 28 March 2018 - 03:35 PM
Hello. I've got an error about a missing 'end' in my program, but every if is closed with an end. Do you find what's causing the error?

Code here

Error:

bios.lua:14: [string "apt"]:96: 'end' expected (to close 'if' at line 68)
SquidDev #2
Posted 28 March 2018 - 03:39 PM
One should use elseif instead of else if. The latter is actually parsed as:

if #args > 2 then
  ...
else
  if a1 == "remove" then
  else
    if a2 == "reinstall" then
       --# etc...
CRUGG #3
Posted 28 March 2018 - 07:38 PM
One should use elseif instead of else if. The latter is actually parsed as:

if #args > 2 then
  ...
else
  if a1 == "remove" then
  else
	if a2 == "reinstall" then
	   --# etc...

I always code using else if and it should work like this:

if arg1 == "test1" then
    ...
else if arg1 == "test2" then
    ...
else
    ...
end
Edited on 28 March 2018 - 05:38 PM
KingofGamesYami #4
Posted 28 March 2018 - 07:57 PM
Not in lua it shouldn't.

https://www.lua.org/pil/4.3.1.html
SquidDev #5
Posted 28 March 2018 - 07:59 PM
I always code using else if and it should work like this:
This form sort of makes sense in C-derived languages, where else statements don't require braces. However, in languages without braces (Lua, Perl, Python, Ruby), you get some merged elseif token instead. On the bright side, it helps resolve some forms of ambiguity.