<foreach> Task

# <foreach>

Loops over a set of items.

Can loop over files in directory, lines in a file, etc.

The property value is stored before the loop is done, and restored when the loop is finished.

The property is returned to its normal value once it is used. Read-only parameters cannot be overridden in this loop.

### Parameters

Attribute | Type | Description | Required
--- | --- | --- | ---
item | LoopItem | The type of iteration that should be done. | True
property | string | The NAnt property name(s) that should be used for the current iterated item. | True
delim | string | The deliminator char. | False
in | string | The source of the iteration. | False
trim | LoopTrim | The type of whitespace trimming that should be done. The default is `None`. | False
failonerror | bool | Determines if task failure stops the build, or is just reported. The default is true. | False
if | bool | If true then the task will be executed; otherwise, skipped. The default is true. | False
unless | bool | Opposite of `if`. If false then the task will be executed; otherwise, skipped. The default is false. | False
verbose | bool | Determines whether the task should report detailed build log messages. The default is false. | False

### Nested Elements:

#### <in>

Stuff to operate in. Just like the `in` attribute, but supports more complicated things like a <fileset> and such.

Note: Please remove the `in` attribute if you are using this element.

### Nested Elements:

#### <items>

#### </items>

#### </in>

#### <do>

Tasks to execute for each matching item.

Executes embedded tasks in the order in which they are defined.

### Parameters

Attribute | Type | Description | Required
--- | --- | --- | ---
failonerror | bool | Determines if task failure stops the build, or is just reported. The default is true. | False
if | bool | If true then the task will be executed; otherwise, skipped. The default is true. | False
unless | bool | Opposite of `if`. If false then the task will be executed; otherwise, skipped. The default is false. | False
verbose | bool | Determines whether the task should report detailed build log messages. The default is false. | False

#### </do>

### Examples

- Loops over the files in `c:\`.

      <foreach item="File" in="c:\" property="filename">
          <echo message="${filename}" />
      </foreach>

- Loops over all files in the project directory.

      <foreach item="File" property="filename">
          <in>
              <items>
                  <include name="**" />
              </items>
          </in>
          <do>
              <echo message="${filename}" />
          </do>
      </foreach>

- Loops over the folders in `c:\`.

      <foreach item="Folder" in="c:\" property="foldername">
          <echo message="${foldername}" />
      </foreach>

- Loops over all folders in the project directory.

      <foreach item="Folder" property="foldername">
          <in>
              <items>
                  <include name="**" />
              </items>
          </in>
          <do>
              <echo message="${foldername}" />
          </do>
      </foreach>

- Loops over a list.

      <foreach item="String" in="1 2,3" delim=" ," property="count">
          <echo message="${count}" />
      </foreach>

- Loops over lines in the file `properties.csv`, where each line is of the format name,value.

      <foreach item="Line" in="properties.csv" delim="," property="x,y">
          <echo message="Read pair ${x}=${y}" />
      </foreach>

### Requirements

Assembly: NAnt.Core (0.92.4543.0)