| 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>while</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="verdicttype.html" alt="previous"><img border="0" src="../images/left.jpg" width="53" height="40"></a></td> |
| 31 |
<td><a href="with.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>while</h1> |
| 38 |
<hr align="left" width="75%"> |
| 39 |
<p>The keyword is used... |
| 40 |
<ol> |
| 41 |
<li><a href="#keyword">alone</a> to define a loop where the loop condition is checked before of each new loop iteration (see below);</li> |
| 42 |
<li>together with the keyword <a href="do.html"><b><font face="Courier New" color="#003258" size="4">do</font></b></a> to define a loop where the loop condition is checked before of each new |
| 43 |
loop iteration.</li> |
| 44 |
</ol> |
| 45 |
<hr align="left" width="50%"> |
| 46 |
<p>The <a name="keyword"> keyword</a> defines on its own a loop which is executed as long as the loop condition holds. The loop condition shall be checked at the beginning of each new loop |
| 47 |
iteration. If the loop condition does not hold, then the loop is exited and execution shall continue with the statement, which immediately follows the loop.</p> |
| 48 |
<hr align="left" width="50%"> |
| 49 |
<div align="center"> |
| 50 |
<center> |
| 51 |
<table border="0" width="90%" bgcolor="#FFB599" cellpadding="4"> |
| 52 |
<tr> |
| 53 |
<td width="100%"> |
| 54 |
<h3 align="center"><font face="Courier New" color="#003258" size="5"><b>while (</b></font><i> condition</i><font face="Courier New" color="#003258" size="5"><b>) {</b></font> <i> |
| 55 |
statement_block </i><font face="Courier New" color="#003258" size="5"><b>};</b></font></h3> |
| 56 |
</td> |
| 57 |
</tr> |
| 58 |
</table> |
| 59 |
</center> |
| 60 |
</div> |
| 61 |
<ul> |
| 62 |
<li> |
| 63 |
<p>The <font face="Courier New" color="#003258" size="4"><b>while</b></font> keyword introduces the loop.</p> |
| 64 |
</li> |
| 65 |
<li> |
| 66 |
<p><i>condition</i> is a Boolean expression. It is checked at the beginning of each new loop iteration. If it evaluates to false, the loop terminates.</p> |
| 67 |
</li> |
| 68 |
<li> |
| 69 |
<p><i>statement_block</i> contains one or more statements. The block will be executed in a loop provided <i>condition</i> is true.</p> |
| 70 |
</li> |
| 71 |
</ul> |
| 72 |
<hr align="left" width="50%"> |
| 73 |
<p>Example 1: |
| 74 |
<p><font face="Courier New">var integer i := 3; <br> |
| 75 |
while (i<=10) {i:= i+2 }<br> |
| 76 |
</font> |
| 77 |
<p>The loop variable i is declared in the first line and it is given the initial value 3. In the second line, a loop is defined. The loop execution terminates when the index value will have |
| 78 |
a value greater than 10. In the statement block the index variable is increased by 2 every time the loop is executed. The loop will be executed 5 times.</p> |
| 79 |
<hr align="left" width="25%"> |
| 80 |
<hr align="left" width="25%"> |
| 81 |
<p><a HREF="BNF.html#whilestatement">BNF definition</a> of <font face="Courier New">while</font></p> |
| 82 |
</body> |
| 83 |
</html> |