121 users using DBSP now!
home -> documentation -> environment guide -> Defined loops: The FOR tag

A loop allows you to execute a statement or block of statements repeatedly. The need of repeat a block of code arises in almost every program.

The FOR Tag

The main purpose of the for-loop is to execute a block of code a given number of times. The general syntax of the FOR tag is described below:

<#FOR STARTIN="a" ENDIN="b">
  …
<#/FOR>

In this case, the block will be inserted b-a+1 times, where a and b are integer values.

Another variation of the FOR tag is described below:

<#FOR NAME="varname" STARTIN="a" ENDIN="b">
  …
<#/FOR>

In this case, the current value of the cycle will be assigned to a variable named as varname and you could use this value for your convenience.

Note: In order to avoid infinite loops that could cause a server crash, the maximum iterations that could be executed are by default 6,500. If the code iterates more times than this value, an exception is raised.

Examples

Example 1. FOR tag basis.

This example shows a very basic use of the FOR Tag.

Source code
Test example


Example 2. For with variation

Same as the above example, but using the FOR variation instead.

Source code
Test example

Previous | Next