Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

While and do loops

The while and do loop functions of the template language, their syntax with sequence, delimiter, break, continue and skip, and why foreach is almost always the better choice.

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/designers/templates/while-and-do-loops.md

On this page

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

  1. while
  2. do ... while
  3. When to use them

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 $level}

The 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.

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.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x