The range operator can be used in conjunction with #set and #foreach statements. Useful for its ability to produce an object array containing integers, the range operator has the following construction:
Both n and m must either be or produce integers. Whether m is greater than or less than n will not matter; in this case the range will simply count down. Examples showing the use of the range operator as provided below:
First example: #foreach( $foo in [1..5] ) $foo #end Second example: #foreach( $bar in [2..-2] ) $bar #end Third example: #set( $arr = [0..1] ) #foreach( $i in $arr ) $i #end 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 that the range operator only produces the array when used in conjunction with #set and #foreach directives, as demonstrated in the fourth example.
Web page designers concerned with making tables a standard size, but where some will not have enough data to fill the table, will find the range operator particularly useful.