If your keys are unique, your data structure. The point of a table key is direct access to the corresponding value.
This has the same effect as your loop:
local v = t[s] -- value for s or nil if s is not a key
if v != nil then
z = v * 10
end
(Or, more exactly the same: local v = rawget(t,s)
to account for cases where t
has an __index
metamethod.)
If we can assume that v will never be false
(which would cause an error at false * 10
) then it can be written more naturally (which skips that error):
local v = t[s]
if v then
z = v * 10
end