While and do loops
This page is for designers who meet {while} or {do} in a template. Both repeat while a condition holds. In design
templates they are rare: most loops go over a list, which {foreach} does better (Foreach loops).
Contents
while
From lib/eztemplate/classes/eztemplatewhilefunction.php:
{while <condition> [sequence <array> as $seqVar]}
[{delimiter}...{/delimiter}]
[{break}] [{continue}] [{skip}]
{/while}def $level = $node.depth
while gt( $level, 1 )
<span class="indent"></span>
set $level = $level|dec
/while
undef $levelThe condition is checked before each run; change a variable in the body or the loop never ends.
do ... while
From lib/eztemplate/classes/eztemplatedofunction.php:
{do}
...
{/do while <condition> [sequence <array> as $seqVar]}The body runs once before the condition is checked.
When to use them
Almost never in a design. Counting is clearer with {for} (For loops), lists with {foreach}. A
runaway loop renders until PHP's time limit; the template engine's template.ini [ControlSettings] MaxLevel limits
nesting of templates, not loop runs.
Related pages
- Foreach loops
- For loops
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.