return
has a really nice functionality where it acts like a validation statement:
--!strict
local mightExist: number?
if mightExist then
mightExist += 1 --> valid
end
--!strict
local mightExist: number?
if not mightExist then
return --> guard clause
end
mightExist += 1 --> valid
continue
, unfortunately, does not have the feature:
--!strict
for i = 1, 10 do
local mightExist: number?
if not mightExist then
continue --> guard clause
end
-->> proceeding line will only run if var "mightExist" is a number
mightExist += 1 --> Type 'number?' cannot be converted to 'number'
end
The above snippet will always spur out predictable valid code, so it should be treated as such.