# Quick overview

181

Before learning every feature in details, let's overview the basics of Lua syntax.

## Variables

You don't need some special keyword to define a variable, you just define them right away, like you do in PHP for example. Also, you don't need to end the expression with some special token like semicolon:

``````name = "Sam"
wallet = 100``````

You can define or reassign multiple variables in a single expression like that:

``name, email = "Sam", "admin@samblog.com"``

## Control flow

`if` statement:

``````if a > b then
print("a is greater than b")
end``````

`while` statement:

``````while a < b do
a = next(a)
end``````

`for` statement:

``````for i = 1, 10 do
print(i)
end``````

`repeat-until` statement:

``````repeat
a = next(a)
until a >= b``````

## Functions

Function example:

``````function add(a, b)
return a + b
end

Anonymous functions are supported as well:

``````function apply(value, fun)
return fun(value)
end

print(apply(15, function(value) return value * 10 end))``````

## Arrays and tables

Defining an array:

``````primes = {2, 3, 5, 7, 11, 13}

print(primes)``````

Defining a table:

``````person =
{
name = "Sam",
wallet = 100
}

print(person.name)``````

There are two types of comments in Lua:

``````-- This is a single-line comment
print("Foo")

--[[ This is
a multiline
comment --]]

print("Bar")``````

Alright, now you have a taste of basic Lua syntax constructions. Let's learn them one by one in details now.

Rate this post:

Lesson 2

Lesson 4