2 Copyright (c) 2000-2016 Ericsson Telecom AB
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Eclipse Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/epl-v10.html
17 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8">
18 <meta http-equiv=
"Content-Language" content=
"en-us">
21 <body bgcolor=
"#DAD3C5" vlink=
"#0094D2" link=
"#003258">
22 <table align=
"left" border=
"0" cellspacing=
"0" cellpadding=
"0" valign=top
>
24 <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>
27 <table border=
"0" align=
"right" cellpadding=
"0" cellspacing=
"0">
29 <td><a href=
"../titan_main.html" alt=
"contents"><img border=
"0" src=
"../images/ao.jpg" width=
"53" height=
"40"></a></td>
30 <td><a href=
"../titan_index.html" alt=
"index"><img border=
"0" src=
"../images/up.jpg" width=
"53" height=
"40"></a></td>
31 <td><a href=
"float2str.html" alt=
"previous"><img border=
"0" src=
"../images/left.jpg" width=
"53" height=
"40"></a></td>
32 <td><a href=
"friend.html" alt=
"next"><img border=
"0" src=
"../images/right.jpg" width=
"53" height=
"40"></a></td>
39 <hr align=
"left" width=
"75%">
40 <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
43 <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>
45 <hr align=
"left" width=
"50%">
48 <table border=
"0" width=
"90%" bgcolor=
"#FFB599" cellpadding=
"4">
51 <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"
52 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>)
53 {
</b></font> <i> statement_block
</i><font face=
"Courier New" color=
"#003258" size=
"5"><b>};
</b></font></h3>
61 <p>The
<font face=
"Courier New" color=
"#003258" size=
"4"><b>for
</b></font> keyword introduces the loop.
</p>
64 <p><i>index_variable_declaration
</i> is optional. When used, the variable will only be visible within the loop.
</p>
67 <p><i>initial_value
</i> is used to initialize the index (or counter) variable of the loop.
</p>
70 <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>
73 <p><i>manipulator_expression
</i> is stepping the index variable after each new loop iteration.
</p>
76 <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>
79 <hr align=
"left" width=
"50%">
81 <p><font face=
"Courier New">var integer j;
<br>
82 for (j:=
1; j
<=
10; j:= j+
2) { log (
"index variable:
", j) }
<br>
84 <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
85 loop 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
86 five lines in the log.
</p>
87 <hr align=
"left" width=
"25%">
89 <p><font face=
"Courier New">for (var integer jj:=
1; jj
<=
10; jj:= jj+
2) { log (
"index variable:
", jj) }
<br>
91 <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>
92 <hr align=
"left" width=
"25%">
93 <hr align=
"left" width=
"25%">
94 <p><a HREF=
"BNF.html#forstatement">BNF definition
</a> of
<font face=
"Courier New">for
</font></p>