# 1.7 break

    break [ <loopname> ]

The `break` command terminates execution of `do`, `while`, `for` and `foreach` loops in an analogous manner to the `break` statement in the C programming language. Execution resumes at the statement following the end of the loop. For example, the following loop would only print the numbers 1 and 2:

    for i = 1 to 10
     {
      print i
      if (i==2)
       {
        break
       }
     }

If several loops are nested, the `break` statement only acts on the innermost loop. If the `break` statement is encountered outside of any loop structure, an error results. Optionally, the `for`, `foreach`, `do` and `while` commands may be supplied with a name for the loop, prefixed by the word `loopname`, as in the examples:

    for i=0 to 4 loopname iloop

    foreach i in "*.dat" loopname DatafileLoop

When loops are given such names, the `break` statement may be followed by the name of the loop whose iteration is to be broken, allowing it to act upon loops other than the innermost one.

See also the `continue` command.