Blocks & control flow ===================== Explicit blocks --------------- Blocks can be explicitly delimited by enclosing a series of statements in curly brackets. .. code-block:: hurdy { var x = 1 -- only visible inside the block print(x) } is translated to .. code-block:: lua do local x = 1 print(x) end If, while, repeat ----------------- Control structures work the same way in Hurdy as they do in Lua, with the difference that word delimiters for blocks (e.g., :code:`do ... end`) are replaced with C-style curly brackets. .. code-block:: hurdy if expr1 { ... } elseif expr2 { ... } else { ... } while expr { ... } repeat { ... } until expr Curly brackets are optional if the block containes a single statement: .. code-block:: hurdy if x == true print("True!") For loops --------- The same applies to for loops, both numeric and generic .. code-block:: hurdy for x = 1, #t { ... } for k,v in ipairs(t) { ... } Curly brackets are optional if the block containes a single statement. Continue statement ------------------ Hurdy includes a :code:`continue` statement that can be used to skip to the end of the current iteration of a loop. This features requires a version of Lua that supports the :code:`goto` statement. Internally this works by translating the :code:`continue` to :code:`goto continue` and adding a :code:`::continue::` label at the end of the loop: .. code-block:: hurdy for i = 1, 10 { if i == 2 continue print(i) } is translated to the Lua code .. code-block:: lua for i = 1, 10 do do if i == 2 then goto continue end print(i) end ::continue:: } The inner block of the loop in enclosed in an additional explicit block to allow nested :code:`continue` statements. Break & return -------------- :code:`break` and :code:`return` statements work the same as in Lua, with the difference that when compiled they are always wrapped in a :code:`do ... end` block. This allows to return or break in the middle of a block/chunk.