Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

what is ";" used for ????

Asked by
IcyEvil 260 Moderation Voter
10 years ago

I have NO idea of what it is Used For.

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

The semicolon ends statements explicitly.

It is optional in almost all cases:

a = 3;
b = 4;
a = b;
function blah(u)
    print(u + 9);
    if u >= 3 then
        blah(u % 3);
    end
end
blah(9);
blah(a + b * 7);

The above snippet acts exactly the same if you remove all of the semicolons.


However, there are cases where they are necessary:

a = b;
(c).d();

The first semicolon is required here, because an equivalent statement when you remove the new line (Lua always ignores all space characters) would be this:

a = b(c).d()

That is, function application of c onto the function b.

Some languages require semicolons after all statements, so some Lua programmers do this out of habit or consistency with their own programming styles from other languages. I am one of these people.

You do not have to use semicolons if you do not want to. Personally, I like to use them for the consistency of when they are required in Lua, and also because it's faster for me to think in programming when I use it everywhere.

Ad

Answer this question