Q:

How to use dynamic array in ant?

I hope to use a dynamic array as follows: 
<property array name = "colors">
   <val = "red">
   <val = "green">
   <val = "blue">
 </property array>

 for (i = 0; i < ${colors}; i++) { 
    <echo file="myfile.txt" append="yes" message="${colors[i]}" />
 } 

is there any way to do it???
Here length is changed
Not fixed
Thanks

A:

Short answer: No.
Ant isn't a programming language as you say. It's a dependency matrix build language. You give Ant directions how to build components and the relationship those components have. Basic Ant has few data structures or even control structures. In basic Ant, properties are immutable.
There are several sets of extension tasks in Ant. The most popular one is Ant-Contrib. Ant-Contrib does have a <for/> task that can act sort of like a for loop, but it's limited in how it works. Here's one way to do what you want:
<for param="color" list="a,b,c">
    <sequential>
        <echo file="myfile.txt" append="yes" messsage="@{color}"/>
    </sequential>
<for>

HOWEVER, you must download the antcontrib jar file, and use <taskdef/> to be able to use Ant-Contrib tasks.
What are you trying to do? If you want a general purpose scripting language, use something like Python, Ruby, or Perl.

