Statements>Loop Statements
Introduction Installation Beginning Admin Quick Ref FTP Server SMTP Server Database Security
Statements Objects String Parsing Events Queues Samples Special names Error Handling Accessories   Back
Caravan Business Server>Help>Statements>Loop Statements
Syntax
<CARAVAN>

loop counter variable (end value of the counter)
...
Any number of HTML/Caravan statements can be included
......
break
...

repeat variable name of the loop counter( end value of the counter)
</CARAVAN>
Text   Loop statements allow you to execute one or more lines of code repetitively. When we know that we must execute a statement a specific number of times then we use the loop statement. The loop statement uses a counter variable that increases in value during each repetition of the loop.
Sample
Example -1 Break
<HTML>
<BODY>
<CARAVAN>
loop ctr (100)
      "The value of the counter is "
      ctr(counter)
      if ctr(counter) = "50"
            break
repeat ctr 101
</CARAVAN>
</BODY>
</HTML>

Loop statements in Caravan can be nested to any number of levels.

End value of the loop statement can be replaced with a variable. But the end value of a repeat statement has to be a constant. Loops can be used to display array values and record sets directly.  

Example - 2 Counter
<HTML>
<BODY>
<CARAVAN>
var temp
temp(delim)=","
temp(name)="John,Mary,Chris"
loop ctr (temp(name(00)))
      ctr(counter);") ";temp(name(ctr(count)));
repeat ctr 100
</CARAVAN>
</BODY>
</HTML>

Example -3  Count
<HTML>
<BODY>
<CARAVAN>
var temp
temp(delim)=","
temp(name)="John,Mary,Chris"
loop ctr (temp(name(00)))
      ctr(counter);") ";temp(name(ctr(count)));
repeat ctr 100
</CARAVAN>
</BODY>
</HTML>
Quick Reference
Properties Count
Counter
Break
Home       Back