# break

The keyword is used in loops and alt, interleave or call statements and altstep definitions.

The break statement may only be used inside the body of a loop (for, while, do-while) or an alternative of an alt or interleave statement or response and exception handling parts of a call statement or the statement block of an alternative of an altstep definition.

When used in loops or alt, interleave or call statements:
On executing a break statement the innermost, currently executed loop, alt, interleave or call statement is left. Execution continues with the statement following the construct which is left.

When used in altstep definitions (but not inside a loop or an alt, interleave or call statement):
On executing a break statement the altstep is left. If the altstep was explicitly called as an alternative of an alt statement or it was called as default for an alt statement, then the alt statement is also left. If the altstep was explicitly called as an alternative with a statement block, then the statement block is skipped (and the alt statement is left).

Related keyword:

- for
- while
- do-while
- alt
- interleave
- call
- altstep

### break;

Example 1:

`do {
/* ... */
if (cond1) { break; /* the do-while loop is left */ }
/* ... */
for (var integer j:=1; j<=10; j:= j+1) {
/* ... */
if (cond2) { break; /* the for-loop is left but the do-while loop is continued */ }
/* ... */
}
/* ... */
}
`

Example 2:

`interleave {
[] PCO1.receive(integer:?) { /* do something here */ }
[] PCO2.receive(integer:?) { /* do something here, too */ }
[] T.timeout { break; }
}
`

With the usage of the break statement a time limit for the execution of the interleave statement is implemented.

BNF definition of break