LuLua · Lesson 2 of 8
Conditions & Loops
if/then/end, while, and two flavors of for. Lua uses keywords instead of braces — code reads almost like sentences.
◆ Note
Only nil and false are falsy in Lua. The number 0 and the empty string "" are TRUTHY — different from Python, JavaScript, and C. 'x = x or default' is the idiomatic default-value trick.
Only nil and false are falsy in Lua. The number 0 and the empty string "" are TRUTHY — different from Python, JavaScript, and C. 'x = x or default' is the idiomatic default-value trick.
✦ Tip
Lua arrays are 1-indexed, and numeric for is inclusive on both ends — so 'for i = 1, #list' walks a whole list. Fighting years of 0-indexed habit is the main adjustment coming from other languages.
Lua arrays are 1-indexed, and numeric for is inclusive on both ends — so 'for i = 1, #list' walks a whole list. Fighting years of 0-indexed habit is the main adjustment coming from other languages.