Sync with 5.4.0
[deliverable/titan.core.git] / help / info / for.html
CommitLineData
970ed795 1<!--
3abe9331 2 Copyright (c) 2000-2015 Ericsson Telecom AB
970ed795
EL
3
4 All rights reserved. This program and the accompanying materials
5 are made available under the terms of the Eclipse Public License v1.0
6 which accompanies this distribution, and is available at
7 http://www.eclipse.org/legal/epl-v10.html
8 -->
9<html>
10<head>
11<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
12<meta http-equiv="Content-Language" content="en-us">
13<title>for</title>
14</head>
15<body bgcolor="#DAD3C5" vlink="#0094D2" link="#003258">
16<table align="left" border="0" cellspacing="0" cellpadding="0" valign=top>
17 <tr>
18 <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>
19 </tr>
20</table>
21<table border="0" align="right" cellpadding="0" cellspacing="0">
22 <tr>
23 <td><a href="../titan_main.html" alt="contents"><img border="0" src="../images/ao.jpg" width="53" height="40"></a></td>
24 <td><a href="../titan_index.html" alt="index"><img border="0" src="../images/up.jpg" width="53" height="40"></a></td>
25 <td><a href="float2str.html" alt="previous"><img border="0" src="../images/left.jpg" width="53" height="40"></a></td>
26 <td><a href="friend.html" alt="next"><img border="0" src="../images/right.jpg" width="53" height="40"></a></td>
27 </tr>
28</table>
29<p><br clear="all">
30</p>
31<hr>
32<h1>for</h1>
33<hr align="left" width="75%">
34<p>The keyword defines a counter loop. The value of the index variable is increased, decreased or manipulated in such a way that after a certain number of execution loops a termination criterion
35is reached.</p>
36<ul>
37 <li>The index variable can be declared in the statement header. By doing so, the scope of the index variable will be limited to the loop.</li>
38</ul>
39<hr align="left" width="50%">
40<div align="center">
41<center>
42<table border="0" width="90%" bgcolor="#FFB599" cellpadding="4">
43 <tr>
44 <td width="100%">
45 <h3 align="center"><font face="Courier New" color="#003258" size="5"><b>for (</b></font>[ <i>index_variable_declaration</i> ]<i> initial_value</i><font face="Courier New" color="#003258"
46 size="5"><b>;</b></font><i> condition</i><font face="Courier New" color="#003258" size="5"><b>;</b></font><i> manipulator_expression</i><font face="Courier New" color="#003258" size="5"><b>)
47 {</b></font>&nbsp;<i> statement_block </i><font face="Courier New" color="#003258" size="5"><b>};</b></font></h3>
48 </td>
49 </tr>
50</table>
51</center>
52</div>
53<ul>
54 <li>
55 <p>The <font face="Courier New" color="#003258" size="4"><b>for</b></font> keyword introduces the loop.</p>
56 </li>
57 <li>
58 <p><i>index_variable_declaration</i> is optional. When used, the variable will only be visible within the loop.</p>
59 </li>
60 <li>
61 <p><i>initial_value</i> is used to initialize the index (or counter) variable of the loop.</p>
62 </li>
63 <li>
64 <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>
65 </li>
66 <li>
67 <p><i>manipulator_expression</i> is stepping the index variable after each new loop iteration.</p>
68 </li>
69 <li>
70 <p><i>statement_block</i> contains one or more statements. The block will be executed in a loop until <i>condition</i> is true.</p>
71 </li>
72</ul>
73<hr align="left" width="50%">
74<p>Example 1:
75<p><font face="Courier New">var integer j;&nbsp;<br>
76for (j:=1; j&lt;=10; j:= j+2) { log (&quot;index variable: &quot;, j) }<br>
77</font>
78<p>The loop variable j is declared in the first line. In the second line, a loop is defined. The initial value of the index variable (j) is 1. The index variable is increased by 2 every time the
79loop was executed. The loop execution terminates when the index value will have a value greater than 10. The statement block contains a log instruction, which will be executed 5 times resulting in
80five lines in the log.</p>
81<hr align="left" width="25%">
82<p>Example 2:
83<p><font face="Courier New">for (var integer jj:=1; jj&lt;=10; jj:= jj+2) { log (&quot;index variable: &quot;, jj) }<br>
84</font>
85<p>The only difference to the first example is that the index variable (jj) now is declared within the loop. It means that it will not be visible outside the loop.</p>
86<hr align="left" width="25%">
87<hr align="left" width="25%">
88<p><a HREF="BNF.html#forstatement">BNF definition</a> of <font face="Courier New">for</font></p>
89</body>
90</html>
This page took 0.072056 seconds and 5 git commands to generate.