for
The for statement creates a statement loop governed by three expressions, enclosed in parentheses and separated by semicolons.
Syntax
<?ev
for (initialization; condition; expression) {
code block
}
?>
Where...
initialization
An expression or variable declaration. Generally used to start a counter. This expression may optionally declare new variables with the var keyword. |
condition
An expression to be evaluated before each iteration. If this expression evaluates to true, the statement block is executed. |
expression
An expression to be evaluated at the end of each iteration. Generally used to increment a counter. |
code block
One or more statements that execute as long as the condition evaluates to true. In EVML for loop statements must be enclosed within a block statement (enclosed in curly brackets {...}). |
Note: Unlike JavaScript, EVML for
loops require an initialisation, condition and expression
Examples
The following are valid:
<?ev
for (var i=0; i<10; i++) {
print(i);
}
?>
Generally you want to output some HTML, in which case the following example may make more sense:
<?ev
for (var i=0; i<page.children.length; i++) {
var childpage = page.children[i];
?>
<h3>{{ childpage.title }}</h3>
<?ev } ?>