<for>

Takes a counter variable name, initial value (from), a boundary condition expressed either as a final value (to) or as an expression (condition), and an optional increment (defaulting to "1"). The familiar continue and break constructs are also available as tags.

Examples

  • (1) with condition expression
<declare name="I" int="0"/>
<declare name="J" int="0"/>
<for var="i" from="0" condition="$E{${i} &lt; 5}">
	<for var="j" from="0" condition="$E{${j} &amp;lt; 5}">
		<declare name="redeclared" string="OK"/>
		<if condition="$E{${i} + ${j} > 4}">
			<break/>
		</if>
		<if condition="$E{${j} + ${i} &amp;lt; 3}">
			<continue/>
		</if>
		<assign name="J" int="${j}"/>
	</for>
	<if condition="$E{${I} $amp;gt;= 4 }">
		<break/>
	</if>
	<assign name="I" int="${i}"/>
</for>
<declare name="result" string="${I}, ${J}"/>
  • (2) with to boundary condition
<declare name="result"/>
<declare name="i" int="20"/>
<for var="i" to="10" increment="-1">
	<declare name="j" int="5"/>
	<for var="j" to="12">
		<declare name="k" int="0"/>
		   	<for var="k" to="7">
		   		<assign name="result" string="${i} ${j} ${k}"/>
		   	</for>
	</for>
</for>

NOTES

  1. If the from condition is left undefined, the variable is assumed to have been initialized in the scope of the loop; if the named variable does not already exist, the loop task will fail.
  2. The to condition is inclusive (i.e., 'up to and including').
  • No labels