{until}

Renders its content again and again until a condition becomes true.

Loops and trees Tag pairs

Syntax

{until condition} ... {/until}
{until} ... {/until condition}

Parameters

condition
An expression, evaluated again before every pass; the loop ends when it becomes true. Written on the closing tag instead, it is tested after each pass, so the content renders at least once.

Description

{until condition} is {while} with the test turned round: it renders its content for as long as the condition is false, and stops as soon as it is true. {until $count eq 0} reads as the sentence it is - often clearer than the equivalent {while $count ne 0}.

Everything else is shared with {while}, which is the same handler: the condition is evaluated anew before every pass, written on the closing tag ({until} ... {/until condition}) it is tested after each pass so the content renders at least once, and {break}, {cease} and {continue} work inside it.

The loop is stopped after 10000 passes when its condition never becomes true - an error under the strict syntax check - and a missing condition or closing tag is an error too.

Examples

A countdown

The content repeats until the condition becomes true.

Templateexamples/until/1-countdown.pad
{set $left = 5}
<p>{until $left eq 0}{$left}... {decrement $left}{/until}lift-off!</p>
Resultopen alone

5... 4... 3... 2... 1... lift-off!

Until a limit is passed

Doubling a value until it passes 100 - the condition is tested before each pass.

Templateexamples/until/2-doubling.pad
{set $amount = 3}
<ul>
{until $amount gt 100}
  <li>{$amount}</li>
  {set $amount = $amount * 2}
{/until}
</ul>
<p>Stopped at {$amount}.</p>
Resultopen alone
  • 3
  • 6
  • 12
  • 24
  • 48
  • 96

Stopped at 192.

See also

  • {while} Renders its content again and again for as long as a condition holds.
  • {decrement} Takes one off a variable, starting it at -1 when it does not exist yet.
  • {break} Leaves a loop at once: the rest of the current pass is dropped and no further row follows.
  • {cease} Ends a loop gracefully: the current pass finishes, and no further row follows.