{cease}
Ends a loop gracefully: the current pass finishes, and no further row follows.
Syntax
{cease}
{cease 'name'}
Parameters
-
level -
Optional: which loop. The name of an enclosing tag or its
name=('items'), a level number, or a negative offset counting levels up from here. Without it, the nearest enclosing loop - past an{if}, a{case}and any other level that renders once for the row it stands in.
Description
{cease} is the soft stop of a loop. The pass it stands in renders to its end - content after the tag included - and then the loop stops: every row after the current one is dropped. Compare {break}, which also drops the rest of the current pass, and {continue}, which only skips the rest of this pass and goes on.
Inside a {while} or {until}, which has no rows but re-tests its condition, {cease} lets the current pass finish and asks for no further one, whatever the condition says.
The parameter picks the loop as for the other loop-control tags: none for the nearest enclosing loop, past an {if}, a {case} and any other level that renders once for the row, a name ({cease 'orders'}, a tag's name or its name=) for an outer loop, or a level number or negative offset. Ceasing an outer loop from an inner one lets the inner loop finish its rows, and the outer loop ends after the current row. A name no enclosing level has is an error under the strict syntax check.
Examples
Stop after this row
The row that ceases still renders in full; the rows after it do not.
<ol>
{queue}
<li>{$name}{if $name eq 'Carol'}{cease} - last one today{/if}</li>
{/queue}
</ol>
<?php
$queue = [
[ 'name' => 'Alice' ],
[ 'name' => 'Bob' ],
[ 'name' => 'Carol' ],
[ 'name' => 'Dave' ],
[ 'name' => 'Erin' ] ];
?>
- Alice
- Bob
- Carol - last one today
cease, break and continue
The same loop with each of the three: what happens to the rest of the pass and to the rows after it.
<p>cease: {sequence '1..5', name='ceaseN'}[{$ceaseN}{if $ceaseN eq 3}{cease}{/if}.]{/sequence}</p>
<p>break: {sequence '1..5', name='breakN'}[{$breakN}{if $breakN eq 3}{break}{/if}.]{/sequence}</p>
<p>continue: {sequence '1..5', name='contN'}[{$contN}{if $contN eq 3}{continue}{/if}.]{/sequence}</p>
cease: [1.][2.][3.]
break: [1.][2.][3
continue: [1.][2.][3[4.][5.]
Ceasing a while
In a {while} the current pass finishes and no further pass follows, whatever the condition says.
{set $round = 0}
<ul>
{while $round lt 10}
{increment $round}
<li>round {$round}{if $round eq 3}{cease} (the last){/if}</li>
{/while}
</ul>
- round 1
- round 2
- round 3 (the last)
See also
- {break} Leaves a loop at once: the rest of the current pass is dropped and no further row follows.
- {continue} Skips the rest of the current pass of a loop and goes on with its next row.
- {while} Renders its content again and again for as long as a condition holds.
- {sequence} Generates a range, a list or one of 80 mathematical sequences, and iterates its values.