Exiting Loops

  • return [ EXPLIST ]
  • The return statement is used to return values from a function or from a chunk.
  • break
  • The break statement can be used to terminate the execution of a loop, skipping to the next statement after the loop. A break ends the innermost enclosing loop (while, repeat, or for).

Return and break statements can only bewritten as the last statements of a block, otherwise an explicit inner block can used, as in the idiom ‘do return end’, because now return is last statement in the inner block.