Lua 4.0 Unconfirmed variables and conditional statements

This code confuses me.

print(gogo)
if (gogo == true) then
print("yes")
elseif (gogo == false) then
print("no")
end

Why gogo evaluates to true ? Shouldn’t it produce an error?

It does not evaluate to true, it cannot, because there is no boolean type in Lua 4.0.

print(true) - prints "nil"

By default, undefined global variables are zero, so gogo == true. They All are zero.

This code confuses me.

print(gogo)
if (gogo == true) then
print("yes")
elseif (gogo == false) then
print("no")
end

Why does gogo evaluate as true? Shouldn’t it produce an error?

It does not evaluate to true, it cannot, because there is no boolean type in Lua 4.0.

< pre>print(true) – prints “nil”

By default, undefined global variables are zero, so gogo == true. They are all zero.

Leave a Comment

Your email address will not be published.