You can use the #foreach directive to loop through the same text multiple times. For example:
|
<HTML> </BODY> |
Produces the following output:
|
Count to ten. |
This #foreach loop causes $number to be looped over for all of the products in the array [1..10]. Each time through the loop, the next element in the [1..10] array is placed into $number.
The range operator can be used in conjunction with the #foreach statement. Useful for its ability to produce an object array containing integers, the range operator has the following construction:
[n..m]
Both n and m must either be, or produce, integers. Whether m is greater than or less than n will not matter; If m is less than n, the range will simply count down.
Simple examples showing the use of the range operator are provided below:
|
#foreach( $count in [1..5] ) |
Produces the following output:
|
1 2 3 4 5 |
|
#foreach( $countdown in [2..-2] ) |
Produces the following output:
|
2 1 0 -1 -2 |
|
#set( $arr = [0..5] ) |
Produces the following output:
|
0 1 2 3 4 5 |
You can define a List with the #set directive and loop through each item.
For example, if the following model has been loaded into Broadcast:
|
|
Then the following code:
|
|
Produces the following output:
|
The value of Sales is 121 |
Listing all Variables in the Model:
Because $Values is a list of all the variables in your model, you can easily create a list of every variable in your model with the following code:
|
<HTML> |
Read more about lists in the following article: