9.2 Range Operator

The range operator can be used in conjunction with #set and #foreach statements. It creates an array of java.lang.Integer objects:

[n..m]

Both n and m must either be or produce integers. If m is greater than n, the range will count down:

## Range: 1 2 3 4 5
First example:
#foreach( $cnt in [1..5] )
  $cnt
#end

## Range: 2 1 0 -1 -2
Second example:
#foreach( $cnt in [2..-2] )
  $cnt
#end 

## Range: 0 1
Third example:
#set( $range = [0..1] )
#foreach( $cnt in $range )
  $cnt
#end

## Not a range (not in a #set or #foreach directive)
Fourth example:
[1..3]

Produces the following output:

First example: 1 2 3 4 5 Second example: 2 1 0 -1
      -2 Third example: 0 1 Fourth example: [1..3]
[Note]Note

As any other operator, the range operator is only evaluated in Velocity directives!