while

Summary

Creates a while loop.

Usage

{while <condition> [ sequence <array> as $seqVar ]}
    [ {delimiter}...{/delimiter} ]
    [ {break}    ]
    [ {continue} ]
    [ {skip}     ]
{/while}

Description

This construct is the simplest loop mechanism that the template language offers. It tells eZ publish to execute the nested statement(s) repeatedly, as long as a given expression evaluates to TRUE. The value of the expression is checked for every loop iteration (at the beginning of the iteration). If the given expression evaluates to FALSE from the very beginning, the nested statement(s) will not be executed.

Examples

Example 1

{while ne( $counter, 8 )}
 
    Print this line eight times ({$counter}) <br />
    {set $counter=inc( $counter )}
 
{/while}

If the initial value of $counter is zero, the following output will be produced:

Print this line eight times (0)
Print this line eight times (1)
Print this line eight times (2)
Print this line eight times (3)
Print this line eight times (4)
Print this line eight times (5)
Print this line eight times (6)
Print this line eight times (7)

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2013 eZ Systems AS (except where otherwise noted). All rights reserved.