# 7.6 The `break` and `continue` statements

The `break` and `continue` statements may be placed within loop structures to interrupt their iteration. The `break` statement terminates execution of the smallest loop currently being executed, and Pyxplot resumes execution at the next statement after the closing brace which marks the end of that loop structure. The `continue` statement terminates execution of the current iteration of the smallest loop currently being executed, and execution proceeds with the next iteration of that loop, as demonstrated by the following pair of examples:

`pyxplot> for i=0 to 4`
`pyxplot> {`
`pyxplot> if (i==2) { break ; }`
`pyxplot> print i`
`pyxplot> }`
`0`
`1`
`pyxplot> for i=0 to 4`
`pyxplot> {`
`pyxplot> if (i==2) { continue ; }`
`pyxplot> print i`
`pyxplot> }`
`0`
`1`
`3`
`4`

Note that if several loops are nested, the `break` and `continue` statements only act on the innermost loop. If either statement is encountered outside of a 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` and `continue` statements may be followed by the name of the loop to be broken out of, allowing the user to act on loops other than the innermost one.