# Executing Gradle task unknown times in loop

**URL:** <https://discuss.gradle.org/t/executing-gradle-task-unknown-times-in-loop/2908>\
**Category:** Old Forum Archive\
**Created:** [July 23, 2014, 3:27pm UTC](https://discuss.gradle.org/t/executing-gradle-task-unknown-times-in-loop/2908 "2014-07-23T15:27:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohan\_Raj](https://avatars.discourse-cdn.com/v4/letter/m/7993a0/32.png) [@Mohan\_Raj](https://discuss.gradle.org/u/Mohan_Raj)\
**Post date:** [July 23, 2014, 3:27pm UTC](https://discuss.gradle.org/t/executing-gradle-task-unknown-times-in-loop/2908/1 "2014-07-23T15:27:00Z")

</div>

My project’s ANT target(mkisofsInstaller) generates ISO images based on the CD disks available. i.e. The target runs for n times with each time a parameter mkisofs.dir which holds the path of disks. Please find the code below.

```gradle
<target name="generateISO" depends="init">
      <foreach target="mkisofsInstaller" param="mkisofs.dir" inheritall="true">
         <path>
            <dirset dir="${build.home}\CDROM_Installers">
               <include name="disk*"/>
            </dirset>
         </path>
      </foreach>
 </target>
     <target name="mkisofsInstaller">
  <propertyfile file="${build.diskimages}/disk.number">
         <entry key="mkisofs.disk.number" type="int" operation="+" default="0"/>
      </propertyfile>
  <echo message="Copying documentation to disk 1"/>
  <copy todir="${mkisofs.dir}/Documents">
     <fileset dir="${build.lib.documents}">
     <include name="*.pdf"/>
     </fileset>
  </copy>
                   <echo message="Creating disk image of dir: ${mkisofs.dir}"/>
      <exec dir="${basedir}" executable="mkisofs" failonerror="true">
         <arg value="-l"/>
         <arg value="-J"/>
         <arg value="-R"/>
         <arg value="-r"/>
         <arg value="-VInstaller${mkisofs.disk.number}"/>
         <arg value="-o${build.diskimages}/Installer${mkisofs.disk.number}.iso"/>
         <arg value="${mkisofs.dir}"/>
      </exec>
   </target>

```

I am trying to gradilize the below targets to Gradle tasks where I face difficulty in executing a task in loop.

I tried an option of creating task rules, but I do not know how to pass path as parameter

and also not sure how much time this task needs to called(as there are around 8 to 10 CD disks).

Kindly help!

Thanks, Mohan
