src/littlesugar/namedWhile

Search:
Group by:

Macros

macro namedWhile(expr, outerName, innerName, body: untyped): untyped

Creates a while statement with named blocks so that you can easily leave or continue the while loop in double (or deeper) loop.

For example:

namedWhile(c < 2, outer, inner):
  while d < 2:
    # Leave outer loop
    break outer
    # Continue outer loop
    break inner

This macro create a while loop with a block enclosing the loop and a block inside the loop like this:

block outer:
  while c < 2:
    block inner:
      while d < 2:
        break outer
        break inner

Specify nil to the block name if you don't need to create a outer or inner block.