Increment in Lua

Find this useful? Support us: Star on GitHub 6
Category: Number | Language: Lua

In Lua, you can increment a number by simply adding 1 to it using the + operator or by using the += operator. Here are some examples:

-- Using the + operator
local num = 5
num = num + 1
print(num) -- Output: 6

-- Using the += operator
local num = 5
num += 1
print(num) -- Output: 6

You can also increment a number by any desired value using the + operator. Here's an example:

-- Increment the number by 3
local num = 5
num = num + 3
print(num) -- Output: 8

Note that Lua does not have a built-in ++ operator for incrementing numbers.