Lua MCQs and Answers with Explanation: This article will help aspirants who are in need of top Lua multiple-choice questions to prepare for an interview or placement exam. The Lua coding quiz will enable you to enhance your coding skills by understanding the concepts. Lua is a lightweight, powerful, and versatile scripting language that is widely used in video game development, embedded systems, and other applications that require fast and efficient scripting capabilities. Developed in 1993, Lua has gained popularity among programmers due to its simplicity, flexibility, and ease of integration with other programming languages.
Lua MCQs with Answers
Lua’s lightweight design makes it an ideal choice for resource-constrained systems, while its powerful features and libraries make it suitable for complex applications. This article provides a collection of Lua Quiz Questions with answers to help you test and enhance your knowledge of this popular scripting language. Whether you are a beginner or an experienced programmer, these Top 50 Lua MCQ Questions will challenge you and deepen your understanding of Lua.
Lua Multiple Choice Questions
Name | Lua |
Exam Type | MCQ (Multiple Choice Questions) |
Category | Technical Quiz |
Mode of Quiz | Online |
Top 50 Lua Multiple Choice Questions | Lua Quiz
1. What type of language is Lua?
A) Object-oriented programming language
B) Functional programming language
C) Imperative programming language
D) Markup language
Answer: C) Imperative programming language
Explanation: Lua is an imperative programming language that follows a procedural paradigm of programming.
2. What was the primary purpose behind the development of Lua?
A) Web development
B) Game development
C) Mobile app development
D) AI development
Answer: B) Game development
Explanation: Lua was primarily developed for game development in the early 1990s. It is used as a scripting language for game engines like Unity.
3. Which of the following is true about Lua’s syntax?
A) It is case-insensitive.
B) It is whitespace-sensitive.
C) It is symbol-sensitive.
D) It is not sensitive to any of the above.
Answer: B) It is whitespace-sensitive.
Explanation: Lua’s syntax is whitespace-sensitive, which means the placement of spaces, tabs, and new lines can affect the program’s behavior.
4. What is the operator used for concatenation in Lua?
A) +
B) –
C) &
D) ..
Answer: D) ..
Explanation: The .. operator is used for string concatenation in LuA) For example, “Hello ” .. “World” will result in “Hello World”.
5. Which of the following is not a valid variable name in Lua?
A) myVar
B) _score
C) 1var
D) score2
Answer: C) 1var
Explanation: Lua variable names cannot start with a number, so 1var is not a valid variable name.
6. What is the use of the loadstring function in Lua?
A) To load a Lua module
B) To load a Lua script from a file
C) To convert a string into a function
D) To convert a function into a string
Answer: C) To convert a string into a function
Explanation: The loadstring function in Lua is used to convert a string into a function, which can then be executeD)
7. Which of the following is the correct syntax to define a function in Lua?
A) function myFunction()
B) def myFunction()
C) function myFunction
D) def function myFunction()
Answer: A) function myFunction()
Explanation: The correct syntax to define a function in Lua is function functionName().
8. What is the scope of a local variable in Lua?
A) Global scope
B) Local scope
C) Function scope
D) Class scope
Answer: C) Function scope
Explanation: Local variables in Lua have function scope, which means they are only accessible within the function they are defined in.
9. Which of the following is the correct syntax to define a table in Lua?
A) {key1 = value1, key2 = value2}
B) {value1, value2}
C) {key1: value1, key2: value2}
D) [key1 = value1, key2 = value2]
Answer: A) {key1 = value1, key2 = value2}
Explanation: The correct syntax to define a table in Lua is {key1 = value1, key2 = value2}.
10. What is the output of the following code?
function myFunction(x)
if x < 0 then
return “Negative”
elseif x > 0 then
return “Positive”
else
return “Zero”
end
end
print(myFunction(5))
A) “Negative”
B) “Positive”
C) “Zero”
D) Error
Answer: B) “Positive”
Explanation: The function takes an argument x and returns “Negative” if x is less than 0, “Positive” if x is greater than 0, and “Zero” if x is equal to 0. The argument passed to the function is 5, which is greater than 0, so the output is “Positive”.
11. What is the output of the following code?
myTable = {1, 2, 3, 4}
print(myTable[5])
A) nil
B) 0
C) Error
D) “”
Answer: A) nil
Explanation: The myTable variable is assigned a table containing four elements. The element at index 5 does not exist, so the output is nil.
12. What is the output of the following code?
myString = “Hello World”
print(myString:sub(1, 5))
A) “Hello”
B) “World”
C) “Hello ”
D) “World ”
Answer: A) “Hello”
Explanation: The :sub() function is used to extract a substring from the string. The arguments passed to the function are 1 and 5, which means the function will extract the first five characters of the string. The output is “Hello”.
13. What is the output of the following code?
myTable = {a = 1, b = 2, c = 3}
for key, value in pairs(myTable) do
print(key .. ” = ” .. value)
end
A) a = 1, b = 2, c = 3
B) 1 = a, 2 = b, 3 = c
C) a = b = c
D) Error
Answer: A) a = 1, b = 2, c = 3
Explanation: The pairs() function is used to iterate over a table. In each iteration, the key and value of the current element are assigned to the variables key and value, respectively. The print() function is used to output the key and value in a formatted string.
14. What is the output of the following code?
function myFunction()
print(“Hello World”)
end
myFunction()
A) “Hello World”
B) Error
C) “”
D) nil
Answer: A) “Hello World”
Explanation: The function definition is followed by a call to the function, which executes the code inside the function. The code inside the function prints “Hello World” to the console.
15. What is the output of the following code?
myTable = {a = 1, b = 2, c = 3}
myTable.d = 4
print(#myTable)
A) 3
B) 4
C) Error
D) “”
Answer: A) 3
Explanation: The # operator is used to get the length of a table. The length of the table is the number of elements in the table with consecutive integer keys starting at A) In this case, there are three elements with consecutive integer keys, so the length of the table is C)
16. What is the output of the following code?
function myFunction(x)
return x * 2
end
myTable = {1, 2, 3}
myNewTable = {}
for i, v in ipairs(myTable) do
myNewTable[i] = myFunction(v)
end
print(myNewTable[2])
A) 2
B) 4
C) 6
D) Error
Answer: B) 4
Explanation: The code defines a function myFunction() that takes an argument x and returns x * B) It then defines a table myTable containing three elements. The code then creates a new table myNewTable and uses a for loop to iterate over the elements of myTable, calling myFunction() on each element and storing the result in the corresponding index of myNewTable. Finally, it prints the second element of myNewTable, which is 4 (since myFunction(2) returns 4).
17. What is the output of the following code?
myTable = {a = 1, b = 2, c = 3}
print(myTable[“b”])
A) 1
B) 2
C) 3
D) nil
Answer: B) 2
Explanation: The code defines a table myTable containing three key-value pairs. It then uses square brackets to access the value associated with the key “b”, which is B)
18. What is the output of the following code?
myString = “Lua is a scripting language”
print(string.find(myString, “a”))
A) 3
B) 6
C) 7
D) Error
Answer: A) 3
Explanation: The string.find() function searches a string for a pattern and returns the starting index of the first occurrence of the pattern. In this case, the pattern is the letter “a”, which appears at index 3 in the string.
19. What is the output of the following code?
function myFunction(x)
if x < 0 then
error(“x must be non-negative”)
end
return x * 2
end
print(myFunction(-2))
A) “x must be non-negative”
B) -4
C) 0
D) Error
Answer: A) “x must be non-negative”
Explanation: The function definition includes a conditional statement that throws an error if the argument x is less than 0. The code then calls the function with an argument of -2, which causes the error to be thrown and the program to terminate with the error message “x must be non-negative”.
20. What is the output of the following code?
myTable = {“Lua”, “is”, “awesome”}
print(table.concat(myTable, ” “))
A) “Lua is awesome”
B) “Lua isawesome”
C) “Lua, is, awesome”
D) Error
Answer: A) “Lua is awesome”
Explanation: The table.concat() function takes a table and returns a string that is the concatenation of all its elements, separated by the delimiter specified as the second argument. In this case, the delimiter is a space character, so the output is “Lua is awesome”.
21. What is the output of the following code?
x = 1
repeat
print(x)
x = x + 1
until x > 3
A) 1 2 3
B) 1 2 3 4
C) 2 3 4
D) Error
Answer: A) 1 2 3
Explanation: The repeat…until loop executes the block of code at least once and then continues to execute it as long as the specified condition is false. In this case, the code block prints the value of x and increments it by 1, and the loop continues until x is greater than C) Therefore, the output is “1 2 3”.
22. What is the output of the following code?
function myFunction(x, y, …)
print(x, y)
local args = {…}
for i, v in ipairs(args) do
print(i, v)
end
end
myFunction(1, 2, 3, 4, 5)
A) 1 2, 1 3, 2 4, 3 5
B) 1 2, 3 4, 5 nil
C) 1 2, 3 4 5 nil
D) Error
Answer: B) 1 2, 3 4, 5 nil
Explanation: The function definition includes three parameters, x, y, and the varargs operator (…), which allows the function to accept a variable number of arguments. The code then calls the function with five arguments, and the function prints the values of x and y, followed by a for loop that iterates over the remaining arguments and prints their index and value. Therefore, the output is “1 2, 3 4, 5 nil”.
23. What is the output of the following code?
myTable = {“hello”, “world”}
for i, v in pairs(myTable) do
print(i, v)
end
A) 1 hello, 2 world
B) hello world
C) “i” “hello”, “i” “world”
D) Error
Answer: A) 1 hello, 2 world
Explanation: The pairs() function returns an iterator that can be used to traverse all key-value pairs in a table, regardless of the type of the keys. The for loop iterates over the key-value pairs in myTable and prints the index and value of each element. Therefore, the output is “1 hello, 2 world”.
24. What is the output of the following code?
function myFunction()
local x = 0
return function()
x = x + 1
return x
end
end
f = myFunction()
print(f())
print(f())
print(f())
A) 1 2 3
B) 0 1 2
C) 1 1 1
D) Error
Answer: A) 1 2 3
Explanation: The function myFunction returns an anonymous function that increments a local variable x and returns its value. The code then assigns the result of calling myFunction() to the variable f, which creates a closure that holds the value of x. The three subsequent calls to f() each return the value of x after it has been incremented by A) Therefore, the output is “1 2 3”.
25. What is the output of the following code?
x = 10
y = 20
if x > 5 then
local z = x + y
end
print(z)
A) 10
B) 20
C) 30
D) Error
Answer: D) Error
Explanation: The code defines two variables, x and y, and then checks if x is greater than 5. If the condition is true, the code creates a local variable z and initializes it with the sum of x and y. However, the scope of z is limited to the if block, and it cannot be accessed outside of it. Therefore, attempting to print z outside of the if block results in an error.
26. What is the output of the following code?
function myFunction(x)
return x * 2
end
x = 5
y = myFunction(x)
print(y)
A) 5
B) 10
C) 15
D) Error
Answer: B) 10
Explanation: The code defines a function myFunction that takes a single argument x and returns its value multiplied by B) The code then assigns the value 5 to the variable x, calls myFunction with x as its argument, and assigns the result to the variable y. Finally, the code prints the value of y, which is the result of calling myFunction with x, or 10.
27. What is the output of the following code?
x = 5
if x == 5 then
x = 10
elseif x == 10 then
x = 20
else
x = 30
end
print(x)
A) 5
B) 10
C) 20
D) 30
Answer: B) 10
Explanation: The code defines the variable x and checks if it is equal to 5. If the condition is true, the code sets x to 10. If x is equal to 10, the code sets it to 20. Otherwise, the code sets x to 30. Since the value of x is 5 at the beginning of the code, the first condition is true and x is set to 10. Therefore, the output is 10.
28. What is the output of the following code?
function myFunction(x, y)
return x + y
end
x = myFunction(“hello”, “world”)
print(x)
A) “helloworld”
B) “hello world”
C) “2”
D) Error
Answer: A) “helloworld”
Explanation: The code defines a function myFunction that takes two arguments x and y and returns their sum. The code then calls myFunction with the strings “hello” and “world” as its arguments, which causes the function to concatenate them into a single string, “helloworld”, since the + operator is overloaded for strings to mean concatenation. Therefore, the output is “helloworld”.
29. What is the output of the following code?
myTable = {“hello”, “world”}
for i, v in ipairs(myTable) do
myTable[i] = v .. “!”
end
for i, v in ipairs(myTable) do
print(v)
end
A) hello, world
B) hello!, world!
C) hello!, world
D) hello, world!
Answer: B) hello!, world!
Explanation: The code defines a table myTable with two elements, “hello” and “world”. The first for loop iterates over the elements of myTable using the ipairs iterator, which returns both the index i and the value v of each element in order. For each element, the code concatenates an exclamation mark to the end of the value and assigns the result back to the table at the same index. Therefore, after the first loop, myTable contains the values “hello!” and “world!”. The second loop then iterates over myTable again and prints each value on a separate line. Therefore, the output is “hello!” followed by “world!”.
30. What is the output of the following code?
function myFunction(x)
if type(x) == “number” then
return x * 2
else
return “invalid input”
end
end
x = “hello”
y = myFunction(x)
print(y)
A) “hellohello”
B) “invalid input”
C) 2
D) Error
Answer: B) “invalid input”
Explanation: The code defines a function myFunction that takes a single argument x and checks if it is a number. If it is, the function returns its value multiplied by B) Otherwise, the function returns the string “invalid input”. The code then assigns the string “hello” to the variable x, calls myFunction with x as its argument, and assigns the result to the variable y. Since x is not a number, myFunction returns the string “invalid input”, which is then printed to the console. Therefore, the output is “invalid input”.
31. What is the output of the following code?
function myFunction(x, y)
if x > y then
return x
else
return y
end
end
x = 10
y = 5
z = myFunction(x, y)
print(z)
A) 5
B) 10
C) 15
D) Error
Answer: B) 10
Explanation: The code defines a function myFunction that takes two arguments x and y and checks if x is greater than y. If x is greater, the function returns x. Otherwise, it returns y. The code then assigns the values 10 and 5 to the variables x and y, respectively, calls myFunction with x and y as its arguments, and assigns the result to the variable z. Since x is greater than y, myFunction returns x, or 10, which is then printed to the console. Therefore, the output is 10.
32. What is the output of the following code?
x = 5
while x > 0 do
print(x)
x = x – 1
end
A) 5 4 3 2 1
B) 1 2 3 4 5
C) 5
D) Error
Answer: A) 5 4 3 2 1
Explanation: The code defines the loop variable x as 5 and enters a while loop that continues as long as x is greater than 0. Inside the loop, the code prints the value of x and then subtracts 1 from x. Therefore, the first iteration of the loop prints 5 and sets x to 4, the second iteration prints 4 and sets x to 3, and so on, until x is decremented to 0 and the loop exits. Therefore, the output is 5 4 3 2 A)
33. What is the output of the following code?
function myFunction(x)
return x * 2
end
myTable = {2, 4, 6, 8}
for i,v in ipairs(myTable) do
myTable[i] = myFunction(v)
end
print(myTable[3])
A) 6
B) 12
C) {2, 4, 6, 8}
D) Error
Answer: B) 12
Explanation: The code defines a function myFunction that takes a single argument x and returns its value multiplied by B) The code then defines a table myTable with four elements, and enters a for loop that iterates over the elements of myTable using the ipairs iterator. For each element, the code calls myFunction with the value of the element as its argument and assigns the result back to the table at the same index. Therefore, after the loop, myTable contains the values {4, 8, 12, 16}. Finally, the code prints the value of myTable at index 3, which is 1B) Therefore, the output is 1B)
34. What is the output of the following code?
function myFunction(x)
if x == 0 then
return
end
print(x)
myFunction(x – 1)
end
myFunction(5)
A) 1 2 3 4 5
B) 5 4 3 2 1
C) 5
D) Error
Answer: B) 5 4 3 2 1
Explanation: The code defines a function myFunction that takes a single argument x and first checks if x is equal to 0. If it is, the function returns without printing anything. Otherwise, the function prints the value of x and then calls itself with x – 1 as its argument. Therefore, the function prints the values of x from 5 down to 1, in descending order. The code then calls myFunction with an initial value of 5, so the output is 5 4 3 2 A)
35. What is the output of the following code?
x = “hello”
y = 5
z = x + y
print(z)
A) “hello5”
B) 5
C) “invalid input”
D) Error
Answer: D) Error
Explanation: The code assigns the string “hello” to the variable x and the number 5 to the variable y. The code then attempts to add these two values together and assign the result to the variable z. However, since x is a string and y is a number, the addition operator cannot be applied to these values and an error occurs. Therefore, the code produces an error instead of any output.
36. What is the output of the following code?
function myFunction(x)
for i = 1, x do
if i == 3 then
return
end
print(i)
end
end
myFunction(5)
A) 1 2 3
B) 1 2
C) 1 2 3 4 5
D) Error
Answer: B) 1 2
Explanation: The code defines a function myFunction that takes a single argument x and enters a for loop that iterates over the values from 1 to x. Inside the loop, the code checks if the current value of i is equal to C) If it is, the function returns without printing anything else. Otherwise, the function prints the value of i. Therefore, when the code calls myFunction with an initial value of 5, the function prints 1, 2, and then returns when i equals C) The for loop does not continue to iterate over the remaining values, so the output is 1 B)
37. What is the output of the following code?
function myFunction(x)
while x > 0 do
if x == 3 then
x = x – 1
goto continue
end
print(x)
x = x – 1
::continue::
end
end
myFunction(5)
A) 1 2 3 4 5
B) 5 4 2 1
C) 5 4 2
D) Error
Answer: B) 5 4 2 1
Explanation: The code defines a function myFunction that takes a single argument x and enters a while loop that continues as long as x is greater than 0. Inside the loop, the code checks if the current value of x is equal to C) If it is, the code decrements x by 1 and uses the goto statement to jump to the label continue, which is just before the end of the loop. Otherwise, the function prints the value of x, decrements it by 1, and continues with the loop. Therefore, when the code calls myFunction with an initial value of 5, the function first prints 5, then 4, then jumps over the value 3, and prints 2 and 1 before terminating. The output is therefore 5 4 2 A)
38. What is the output of the following code?
function myFunction(x)
local y = 0
repeat
y = y + 1
print(y)
until y >= x
end
myFunction(3)
A) 1 2 3
B) 1 2 3 4
C) 1 2 3 4 5
D) Error
Answer: A) 1 2 3
Explanation: The code defines a function myFunction that takes a single argument x and initializes a local variable y to 0. The function then enters a repeat-until loop that executes at least once and continues until y is greater than or equal to x. Inside the loop, the function increments the value of y by 1 and prints its current value. Therefore, when the code calls myFunction with an initial value of 3, the function prints 1, 2, and 3, and then terminates. The output is therefore 1 2 C)
39. What is the output of the following code?
function myFunction(x)
local y = x
while y > 0 do
print(y)
y = y – 1
end
end
myFunction(“3”)
A) 1 2 3
B) 1 2 3 4
C) 3 2 1
D) Error
Answer: C) 3 2 1
Explanation: The code defines a function myFunction that takes a single argument x and initializes a local variable y to its value. The function then enters a while loop that continues as long as y is greater than 0. Inside the loop, the function prints the current value of y and decrements it by A) The argument x is passed as a string, but since Lua is a dynamically typed language, it can be converted to a number when used in a numeric context such as the comparison y > 0. Therefore, when the code calls myFunction with the argument “3”, the function initializes y to the number 3 and prints 3, then 2, then 1 before terminating. The output is therefore 3 2 A)
40. What is the output of the following code?
function myFunction(x)
if x % 2 == 0 then
return “Even”
else
return “Odd”
end
end
print(myFunction(4), myFunction(5))
A) Even Odd
B) Odd Even
C) Even Even
D) Odd Odd
Answer: A) Even Odd
Explanation: The code defines a function myFunction that takes a single argument x and checks if it is even or odd by calculating its remainder when divided by B) If the remainder is 0, the function returns the string “Even”, otherwise it returns “Odd”. The code then calls the function twice with the arguments 4 and 5, respectively, and uses the print statement to output the two return values separated by a commA) Therefore, the output is “Even Odd”.
41. What is the output of the following code?
function myFunction(x)
if type(x) == “number” then
return x + 1
else
return “Invalid input”
end
end
print(myFunction(4), myFunction(“Hello”))
A) 5 Invalid input
B) Invalid input 5
C) 5 6
D) Invalid input Invalid input
Answer: A) 5 Invalid input
Explanation: The code defines a function myFunction that takes a single argument x and checks if it is a number by using the type function. If x is a number, the function returns its value plus A) Otherwise, it returns the string “Invalid input”. The code then calls the function twice, once with the argument 4 and once with the string “Hello”, and uses the print statement to output the two return values separated by a commA) Therefore, the output is “5 Invalid input”.
42. What is the output of the following code?
function myFunction(x)
local y = x or 1
return y * 2
end
print(myFunction(), myFunction(4))
A) 2 8
B) 1 8
C) 2 4
D) 1 4
Answer: A) 2 8
Explanation: The code defines a function myFunction that takes a single argument x and initializes a local variable y to its value or 1 if x is nil or false. The function then returns the result of y times B) The code then calls the function twice, once without an argument and once with the argument 4, and uses the print statement to output the two return values separated by a commA) Therefore, the output is “2 8”.
43. What is the output of the following code?
function myFunction(x)
for i = 1, x, 2 do
print(i)
end
end
myFunction(5)
A) 1 3 5
B) 1 2 3 4 5
C) 2 4
D) Nothing is printed
Answer: A) 1 3 5
Explanation: The code defines a function myFunction that takes a single argument x and enters a for loop that iterates over the range from 1 to x with a step of B) Inside the loop, the function prints the current value of the loop variable i. Therefore, when the code calls myFunction with the argument 5, the function prints 1, 3, and 5 before terminating. The output is therefore “1 3 5”.
44. What is the output of the following code?
function myFunction(x)
local y = x + 1
return y
end
local z = 5
z = myFunction(z)
print(z)
A) 5
B) 6
C) 10
D) Error
Answer: B) 6
Explanation: The code defines a function myFunction that takes a single argument x and initializes a local variable y to its value plus A) The function then returns the value of y. The code then initializes a local variable z to the value 5, calls the function myFunction with z as an argument, and assigns the return value of the function to z. Finally, the code prints the value of z, which is 6 because myFunction returned 5 + 1 = 6.
45. What is the output of the following code?
x = 3
function myFunction()
x = 4
end
myFunction()
print(x)
A) 3
B) 4
C) Error
D) Nothing is printed
Answer: B) 4
Explanation: The code initializes a global variable x to the value 3 and defines a function myFunction that sets the value of x to D) The code then calls myFunction, which modifies the value of the global variable x to D) Finally, the code prints the value of x, which is D)
46. What is the output of the following code?
function myFunction(x, y)
return x * y, x + y
end
print(myFunction(2, 3))
A) 5 6
B) 6 5
C) 5, 6
D) 6, 5
Answer: A) 5 6
Explanation: The code defines a function myFunction that takes two arguments x and y and returns two values, the product of x and y and the sum of x and y. The code then calls the function with the arguments 2 and 3, and uses the print statement to output the two return values separated by a space. Therefore, the output is “6 5”.
47. What is the output of the following code?
for i = 1, 10, 2 do
print(i)
end
A) 1 3 5 7 9
B) 2 4 6 8 10
C) 1 2 3 4 5
D) 1 2 3 4 5 6 7 8 9 10
Answer: A) 1 3 5 7 9
Explanation: The code uses a for loop to iterate from 1 to 10 with a step of B) During each iteration, the loop variable i takes on the values 1, 3, 5, 7, and 9, and the code uses the print statement to output the value of i on a separate line. Therefore, the output is “1 3 5 7 9”.
48. What is the output of the following code?
x = {a = 1, b = 2, c = 3}
for k, v in pairs(x) do
print(k, v)
end
A) a 1 b 2 c 3
B) 1 2 3
C) {a = 1, b = 2, c = 3}
D) Error
Answer: A) a 1 b 2 c 3
Explanation: The code initializes a table x with three key-value pairs, and uses a for loop with the pairs function to iterate over the table and output each key-value pair on a separate line. Therefore, the output is “a 1 b 2 c 3”.
49. What is the output of the following code?
function myFunction(x)
return x % 2 == 0
end
print(myFunction(3), myFunction(4))
A) false true
B) true false
C) true true
D) false false
Answer: B) false true
Explanation: The code defines a function myFunction that takes a single argument x and returns true if x is even (i.e., divisible by 2), and false otherwise. The code then calls the function twice, once with the argument 3 and once with the argument 4, and uses the print statement to output the two return values separated by a commA) Therefore, the output is “false true”.
50. What is the output of the following code?
x = {3, 2, 1}
table.sort(x)
print(x[1], x[2], x[3])
A) 1 2 3
B) 3 2 1
C) 1 3 2
D) 2 1 3
Answer: A) 1 2 3
Explanation: The code initializes a table x with three values, and uses the table.sort function to sort the values in ascending order. The code then uses the print statement to output the three sorted values on a single line, separated by spaces. Therefore, the output is “1 2 3”.
Lua multiple-choice questions can be an effective tool for enhancing one’s coding skills and preparing for interviews or placement exams. By practicing and familiarizing oneself with various concepts through these Lua MCQs with answers, one can increase their chances of success in the competitive field of programming. To stay ahead in your career advancement, keep following our Freshersnow portal regularly for various articles that can help you.