| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
<html> |
| 15 |
<head> |
| 16 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 17 |
<meta http-equiv="Content-Language" content="en-us"> |
| 18 |
<title>break</title> |
| 19 |
</head> |
| 20 |
<body bgcolor="#DAD3C5" vlink="#0094D2" link="#003258"> |
| 21 |
<table align="left" border="0" cellspacing="0" cellpadding="0" valign=top> |
| 22 |
<tr> |
| 23 |
<td width=105 height=40><a href="https://projects.eclipse.org/projects/tools.titan"><img src="../images/titan_transparent.gif" border=0 width=105 height=40 align="left" alt="Titan"></a></td> |
| 24 |
</tr> |
| 25 |
</table> |
| 26 |
<table border="0" align="right" cellpadding="0" cellspacing="0"> |
| 27 |
<tr> |
| 28 |
<td><a href="../titan_main.html" alt="contents"><img border="0" src="../images/ao.jpg" width="53" height="40"></a></td> |
| 29 |
<td><a href="../titan_index.html" alt="index"><img border="0" src="../images/up.jpg" width="53" height="40"></a></td> |
| 30 |
<td><a href="boolean.html" alt="previous"><img border="0" src="../images/left.jpg" width="53" height="40"></a></td> |
| 31 |
<td><a href="call.html" alt="next"><img border="0" src="../images/right.jpg" width="53" height="40"></a></td> |
| 32 |
</tr> |
| 33 |
</table> |
| 34 |
<p><br clear="all"> |
| 35 |
</p> |
| 36 |
<hr> |
| 37 |
<h1>break</h1> |
| 38 |
<hr align="left" width="75%"> |
| 39 |
<p>The keyword is used in loops and <font face="Courier New"><b>alt</b></font>, <font face="Courier New"><b>interleave</b></font> or <font face="Courier New"><b>call</b></font> statements and <font |
| 40 |
face="Courier New"><b>altstep</b></font> definitions.</p> |
| 41 |
<p>The <font face="Courier New"><b>break</b></font> statement may only be used inside the body of a loop (<font face="Courier New"><b>for</b></font>, <font face="Courier New"><b>while</b></font>, |
| 42 |
<font face="Courier New"><b>do-while</b></font>) or an alternative of an <font face="Courier New"><b>alt</b></font> or <font face="Courier New"><b>interleave</b></font> statement or response and |
| 43 |
exception handling parts of a <font face="Courier New"><b>call</b></font> statement or the statement block of an alternative of an <font face="Courier New"><b>altstep</b></font> definition.</p> |
| 44 |
<p>When used in loops or <font face="Courier New"><b>alt</b></font>, <font face="Courier New"><b>interleave</b></font> or <font face="Courier New"><b>call</b></font> statements:<br> |
| 45 |
On executing a <font face="Courier New"><b>break</b></font> statement the innermost, currently executed loop, <font face="Courier New"><b>alt</b></font>, <font face="Courier New"><b>interleave</b></font> |
| 46 |
or <font face="Courier New"><b>call</b></font> statement is left. Execution continues with the statement following the construct which is left.</p> |
| 47 |
<p>When used in <font face="Courier New"><b>altstep</b></font> definitions (but not inside a loop or an <font face="Courier New"><b>alt</b></font>, <font face="Courier New"><b>interleave</b></font> |
| 48 |
or <font face="Courier New"><b>call</b></font> statement):<br> |
| 49 |
On executing a <font face="Courier New"><b>break</b></font> statement the <font face="Courier New"><b>altstep</b></font> is left. If the <font face="Courier New"><b>altstep</b></font> was explicitly |
| 50 |
called as an alternative of an <font face="Courier New"><b>alt</b></font> statement or it was called as default for an <font face="Courier New"><b>alt</b></font> statement, then the <font |
| 51 |
face="Courier New"><b>alt</b></font> statement is also left. If the <font face="Courier New"><b>altstep</b></font> was explicitly called as an alternative with a statement block, then the statement |
| 52 |
block is skipped (and the <font face="Courier New"><b>alt</b></font> statement is left).</p> |
| 53 |
<hr align="left" width="50%"> |
| 54 |
<p>Related keyword:</p> |
| 55 |
<ul> |
| 56 |
<li><a href="for.html"><b><font face="Courier New" color="#003258" size="4">for</font></b></a></li> |
| 57 |
<li><a href="while.html"><b><font face="Courier New" color="#003258" size="4">while</font></b></a></li> |
| 58 |
<li><a href="do.html"><b><font face="Courier New" color="#003258" size="4">do-while</font></b></a></li> |
| 59 |
<li><a href="alt.html"><b><font face="Courier New" color="#003258" size="4">alt</font></b></a></li> |
| 60 |
<li><a href="interleave.html"><b><font face="Courier New" color="#003258" size="4">interleave</font></b></a></li> |
| 61 |
<li><a href="call.html"><b><font face="Courier New" color="#003258" size="4">call</font></b></a></li> |
| 62 |
<li><a href="altstep.html"><b><font face="Courier New" color="#003258" size="4">altstep</font></b></a></li> |
| 63 |
</ul> |
| 64 |
<hr align="left" width="50%"> |
| 65 |
<div align="center"> |
| 66 |
<center> |
| 67 |
<table border="0" width="90%" bgcolor="#FFB599" cellpadding="4"> |
| 68 |
<tr> |
| 69 |
<td width="100%"> |
| 70 |
<h3 align="center"><font face="Courier New" color="#003258" size="5"><b>break;</b></font></h3> |
| 71 |
</td> |
| 72 |
</tr> |
| 73 |
</table> |
| 74 |
</center> |
| 75 |
</div> |
| 76 |
<hr align="left" width="25%"> |
| 77 |
<P>Example 1: |
| 78 |
<p><code> do {<br> |
| 79 |
/* ... */<br> |
| 80 |
if (cond1) { break; /* the do-while loop is left */ }<br> |
| 81 |
/* ... */<br> |
| 82 |
for (var integer j:=1; j<=10; j:= j+1) {<br> |
| 83 |
/* ... */<br> |
| 84 |
if (cond2) { break; /* the for-loop is left but the do-while loop is continued */ }<br> |
| 85 |
/* ... */<br> |
| 86 |
}<br> |
| 87 |
/* ... */<br> |
| 88 |
}<br></p> |
| 89 |
</code> |
| 90 |
<hr align="left" width="25%"> |
| 91 |
<P>Example 2: |
| 92 |
<p><code> interleave {<br> |
| 93 |
[] PCO1.receive(integer:?) { /* do something here */ }<br> |
| 94 |
[] PCO2.receive(integer:?) { /* do something here, too */ }<br> |
| 95 |
[] T.timeout { break; }<br> |
| 96 |
}<br> |
| 97 |
</code></p> |
| 98 |
<p>With the usage of the <font face="Courier New"><b>break</b></font> statement a time limit for the execution of the <font face="Courier New"><b>interleave</b></font> statement is implemented.</p> |
| 99 |
<hr align="left" width="25%"> |
| 100 |
<p><a HREF="BNF.html#breakstatement">BNF definition</a> of <font face="Courier New">break</font></p> |
| 101 |
</body> |
| 102 |
</html> |