Semicolon Conventions in Lua Programming


There are very few sections we will explore the possibility of making use of a semicolon in Lua. Majority of the code doesn’t require it, while there are some cases where we might need them.

Example

Let’s consider a case where the use of semicolon seems necessary. Consider the example shown below −

 Live Demo

local a,b=10,20
print(a+b)

The above statement in Lua is perfectly valid and it works like a charm.

Output

30

Example

What if we change the code above and put it in the same line? Would it still be a valid Lua code? Let’s try it out. Consider the code shown below −

local a,b =10,20 print(a+b)

The above code in Lua will still work as expected but it doesn’t seem very user friendly and that’s where the use of a semicolon will come in handy.

Example

Consider the example shown below −

 Live Demo

local a,b =10,20;print(a+b)

Output

30

Updated on: 19-Jul-2021

404 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements