Skip to content

<mvt:while>#

Miva Merchant incorporates while Loops, a familiar programming construct found in many programming languages. While Loops provide a mechanism for repeatedly executing a block of code as long as a specified condition remains true. Let’s explore the syntax and functionality of While Loops within Miva Merchant’s template language.

Syntax#

<mvt:while expr="g.counter LTE 10">
    <!-- Loop Body: Code to be executed -->
    Hello World! <br>
    <mvt:assign name="g.counter" expr="g.counter + 1">
</mvt:while>
Attribute Description
expr This attribute defines the condition that the loop evaluates.

Additional Tags#

While Loops in Miva Merchant also support two additional tags to control loop execution:

<mvt:whilestop />#

This tag halts the execution of the loop if a specified condition is met, allowing program flow to continue beyond the loop.

<mvt:whilecontinue />#

Conversely, while continue returns program flow to the beginning of the loop if a condition is met, enabling conditional iteration within the loop.

Examples#

The While Loop iterates through the loop body as long as the condition (g.counter LTE 10) remains true. Within each iteration, “Hello World!” is outputted, and g.counter is incremented by 1 using the mvt:assign tag. This ensures that the loop eventually terminates, preventing an infinite loop scenario.

<mvt:assign name="l.my_value" value="10" />
<mvt:assign name="l.settings:counter" value="0" />
<mvt:while expr="l.settings:counter LE l.my_value">
    The value of counter is: &mvt:counter; <br>
    <mvt:assign name="l.settings:counter" value="l.settings:counter + 1" />
</mvt:while>

Output

The value of counter is: 0
The value of counter is: 1
The value of counter is: 2
The value of counter is: 3
The value of counter is: 4
The value of counter is: 5
The value of counter is: 6
The value of counter is: 7
The value of counter is: 8
The value of counter is: 9
The value of counter is: 10

Summary#

While Loops offer significant flexibility and power within the Miva Merchant template language, providing developers with a versatile tool for iterative processing. By leveraging While Loops effectively, developers can enhance the functionality and dynamics of their Miva Merchant templates.