1.
What is a scope?
Correct Answer
A. A block of code.
Explanation
A scope refers to a block of code where variables, functions, and objects are defined and can be accessed. It determines the visibility and lifetime of these entities within the program. By enclosing code within a scope, it helps in organizing and managing the variables and functions, preventing naming conflicts, and improving code readability. Therefore, the answer "A block of code" accurately describes what a scope is in programming.
2.
What is the difference between a Local Variable and a Global Variable?
Correct Answer
A. Local Variables can only be accessed in the scope they were created in.
Explanation
Local variables are variables that are declared inside a function or a block of code. They have a limited scope and can only be accessed within the function or block of code in which they were created. On the other hand, global variables are declared outside of any function or block of code and can be accessed from anywhere in the program. Therefore, the correct answer is that local variables can only be accessed in the scope they were created in.
3.
What is a while loop?
Correct Answer
C. A loop that runs only while a specified condition is true.
Explanation
A while loop is a type of loop that runs only while a specified condition is true. This means that the loop will continue to execute its code block as long as the condition remains true. Once the condition becomes false, the loop will terminate and the program will move on to the next line of code. This type of loop is commonly used when we want to repeat a certain task until a specific condition is met.
4.
Every scope except those created by repeat loops require an 'end' statement.
Correct Answer
A. True
Explanation
In programming, the 'end' statement is typically used to mark the end of a scope or block of code. This statement is necessary for all scopes except those created by repeat loops. Repeat loops have their own way of indicating the end of the loop, so they do not require an 'end' statement. Therefore, the statement that every scope except those created by repeat loops require an 'end' statement is true.
5.
What is an argument?
Correct Answer
A. A variable that is defined in a function and can only be used for it.
Explanation
An argument is a variable that is defined within a function and can only be used within that function. It allows data to be passed into a function when it is called, allowing the function to perform operations on that data. This helps in making functions more flexible and reusable, as different values can be passed as arguments to achieve different results.
6.
What symbol are values in a table placed in?
Correct Answer
D. {} - braces
Explanation
Values in a table are typically placed within braces {} because braces are commonly used to represent sets or collections of items. In the context of a table, the values within the braces indicate that they belong to a specific row or column, and are grouped together as a set.
7.
How do I iterate (loop through) each key and value in a table?
Correct Answer
B. Use a generic for loop.
Explanation
A generic for loop is used to iterate through each key and value in a table. It is the most efficient and convenient way to loop through a table as it automatically handles the iteration process. The generic for loop syntax allows you to specify the variables that will hold the key and value for each iteration, and the table that you want to iterate through. This loop will iterate through each key-value pair in the table until all elements have been processed.
8.
Which one successfully iterates through a table?
Correct Answer
C. For k,v in pairs(table) do print(k,v) end
Explanation
The correct answer is "for k,v in pairs(table) do print(k,v) end". This is the correct way to iterate through a table using the pairs() function in Lua. It will iterate over each key-value pair in the table and print the key and value.
9.
How you share values through all scripts in the game?
Correct Answer
B. Use the global table (_G). Put variables inside of _G and access them from any script.
Explanation
By using the global table (_G) and putting variables inside it, we can make them accessible from any script in the game. This allows for easy sharing of values between scripts without the need for additional communication methods.