Content added Content deleted
m (order change for correct questions) |
m (revized quiz) |
||
Line 151: | Line 151: | ||
|type="()"} |
|type="()"} |
||
- a = 4 |
- a = 4 |
||
|| This defines <code>a</code> globally - not locally. |
|||
- do a = 4 end |
- do a = 4 end |
||
|| This defines <code>a</code> globally (not locally), and within a scope block. |
|||
+ local a = 4 |
+ local a = 4 |
||
- local a = "4" |
- local a = "4" |
||
|| This defines <code>a</code> locally, but as "4" (a string), not 4 (a number). |
|||
{Defining variables in the local scope is always preferred |
{Defining variables in the local scope is always preferred |
||
Line 159: | Line 162: | ||
+ TRUE |
+ TRUE |
||
- FALSE |
- FALSE |
||
|| Always defining variables in the local scope is less memory intensive and makes you less prone to mistakes |
|||
{What will the following code print? <syntaxhighlight lang="lua" line="1"> |
|||
local hello = "Hello world!" |
|||
print(hello) |
|||
</syntaxhighlight> |
|||
|type="()"} |
|||
- hello |
|||
+ Hello world! |
|||
- "Hello world!" |
|||
- 'hello' |
|||
{Consider the following code: <syntaxhighlight lang="lua" line="1"> |
{Consider the following code: <syntaxhighlight lang="lua" line="1"> |
||
local b = 2 |
local b = 2 |
||
local |
local p = 3 |
||
do |
do |
||
b = 5 |
b = 5 |
||
print( |
print(p) |
||
end |
end |
||
Line 172: | Line 187: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
The code will print out: |
The code will print out: |
||
|type="()"} |
|type="()" coef="2"} |
||
- 5, then 2 |
- 5, then 2 |
||
|| You seem to have mixed up the variables. |
|||
- 2, then 3 |
- 2, then 3 |
||
|| You seem to have mixed up the variables. |
|||
- 3, then 5 |
- 3, then 5 |
||
|| <code>b</code> is equal to 5 only in the scope block; not outside of it. |
|||
+ 3, then 2 |
+ 3, then 2 |
||
Line 194: | Line 212: | ||
If the output of the code was '''54''' and '''24'''. |
If the output of the code was '''54''' and '''24'''. |
||
|type="{}"} |
|type="{}" coef="4"} |
||
First missing line: { print(c) } |
First missing line: { print(c) } |
||
Second missing line: { c=24|s=24|local c = 24|local c=24|local s = 24|local s=24 } |
Second missing line: { c=24|s=24|local c = 24|local c=24|local s = 24|local s=24 } |