如何基于Ant中的限制进行循环 [英] how to do for loop based on a limit in Ant

查看:161
本文介绍了如何基于Ant中的限制进行循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ant-contrib中,我们可以执行以下操作:

In Ant-contrib, we can do something like:

<for list="a,b,c,d" param="instence">

但是,如果我没有列表,则只有一个限制,例如limit = 4。

But if I don't have a list, I only have a limit, e.g. limit=4.

是否有一种基于限制的循环方法,例如:

Is there a way to do for loop based on limit, like:

<for limit="4" param="index">


推荐答案

Ant插件 Flaka 为您的问题提供了一些解决方案。

The Ant addon Flaka provides some solutions for your problem.

1)使用while循环

1) Use a while loop

test属性评估一些EL表达式,
可能是一个简单的计数器fe

the test attribute evaluates some EL expression,
which maybe a simple counter, f.e.

<project name="demo" xmlns:fl="antlib:it.haefelinger.flaka">

 <!-- some counter -->
 <fl:let>
  countdown = 3
 </fl:let>

 <fl:while test=" countdown >= 0 ">
  <fl:echo>
   #{countdown > 0 ? countdown : 'bang!' }..
  </fl:echo>
  <fl:let>
   countdown = countdown - 1
  </fl:let>
 </fl:while>

</project>

输出:

  [fl:echo] 3..
  [fl:echo] 2..
  [fl:echo] 1..
  [fl:echo] bang!..

或其他表达式,例如检查文件是否存在,意味着循环直到某个文件存在:

or some other expression, f.e. checking for existence of a file, means looping until some file exists :

 <fl:while test=" !'/home/rosebud/stop'.tofile.isfile ">
  <fl:echo>
   still working..
  </fl:echo>
 </fl:while>

2)使用带有break或continue的for循环:

2) Use a for loop with break or continue :

<project name="demo" xmlns:fl="antlib:it.haefelinger.flaka">

 <fl:for var="i" in=" list(1,2,3,4,5,6) ">
    <fl:echo>i = #{i}</fl:echo>
    <fl:break test=" i == 3 " />
 </fl:for>

  <fl:for var="i" in=" list(1,2,3,4,5,6) ">
    <fl:continue test=" i > 3 " />
    <fl:echo>i = #{i}</fl:echo>
 </fl:for>

</project>

给出相同的结果:

  [fl:echo] i = 1
  [fl:echo] i = 2
  [fl:echo] i = 3

Flaka手册

See more details in the Flaka manual

这篇关于如何基于Ant中的限制进行循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆