1,004
edits
(finished variables and scope section) |
m (added quiz) |
||
Line 147:
Feel free to play around a little with what you've just learned. Learning by doing is the best way to learn. If anything's been left slightly unclear, try going over everything again once more; perhaps slower. Once you feel you're ready, please take the following quiz to check your comprehension: <quiz display="simple">
{Which of the following defines a to be equal to the number 4 in the local scope?
|type="()"}
- a = 4
- do a = 4 end
+ local a = 4
- local a = "4"
</quiz>▼
{Defining variables in the local scope is always preferred
|type="()"}
+ TRUE
- FALSE
{Consider the following code: <syntaxhighlight lang="lua" line="1">
local b = 2
local x = 3
do
b = 5
print(x)
end
print(b)
</syntaxhighlight>
The code will print out:
|type="()"}
- 5, then 2
- 2, then 3
- 2, then 5
+ 3, then 2
{ Complete the missing lines:<syntaxhighlight lang="lua" line="1">
local c = 32
local s = c
do
c = 54
do
print(s)
...
...
...
end
end
</syntaxhighlight>
If the output of the code was '''54''' and '''24'''.
|type="{}"}
First missing line: { print(c) }
Second missing line: { local c = 24|local c=24|c=24|local s = 24|local s=24|s=24 }
Third missing line: { print(c)|print(s) }
▲</quiz>
- types
|