|
Loops through the code between
Care must be taken to ensure an endless loop is not created. The Empresa engine will eventually time out, but the loop will consume server resources until that happens. The <MvWHILESTOP> command can be used to exit a loop at any time. Attributes
ExamplesExample:<MvWHILE EXPR = "{ condition }"> Execute the code here repeatedly while this condition is true. </MvWHILE> In this example the code executes a fixed number of times. Example:<MvASSIGN name="g.counter" value="1"> <MvWHILE EXPR = "{ Counter LE 10 }"> Execute the code here 10 times. <MvASSIGN name="g.counter" value="{ g.counter + 1}"> </MvWHILE> Breaking out of a loop. Loops can be ended manually using <MvWHILESTOP>, for example when an error is detected, or to prevent an endless loop. Example:<MvWHILE EXPR = "{ 1 }"> Execute the code here endlessly. <MvIF EXPR="{ g.counter GE 100 }"> <MvWHILESTOP> </MvIF> <MvASSIGN name="g.counter" value="{ g.counter + 1}"> </MvWHILE> Often when processing data, the number of loops is often not know in advance so other conditions must be tested. In this example, l.fieldlist is a comma separated list of values and is output to the browser one line at a time. Example:<MvASSIGN NAME="l.posn" VALUE="{ 1 }"> <MvASSIGN NAME="l.item" VALUE="{ gettoken(l.fieldlist,',',l.posn) }"> <MvWHILE EXPR="{ l.item }"> <MvEVAL EXPR="{ l.posn $ '. ' $ l.item }"><br> <MvASSIGN NAME="l.posn" VALUE="{ l.posn + 1 }"> <MvASSIGN NAME="l.item" VALUE="{ gettoken(l.fieldlist,',',l.posn) }"> </MvWHILE>
|