Ant 中断还是继续?
ant contrib中的for/foreach循环是否支持与“break”或“continue”语句等效的语句?据我所知,他们没有 有没有可行的解决办法 谢谢Ant 中断还是继续?,ant,ant-contrib,Ant,Ant Contrib,ant contrib中的for/foreach循环是否支持与“break”或“continue”语句等效的语句?据我所知,他们没有 有没有可行的解决办法 谢谢 -T实现这种行为没有简单的方法,但是下面的建议可能会有所帮助 使用(即,不使用foreach) 将keepgoing属性设置为true 与条件一起使用,以便需要跳过的项目将失败 只要检测到需要中断,就可以通过定义属性myBreakProperty来获得类似中断的内容 <for list="a,b,c,d,e" param=
-T实现这种行为没有简单的方法,但是下面的建议可能会有所帮助
- 使用(即,不使用foreach)
- 将
属性设置为truekeepgoing
- 与条件一起使用,以便需要跳过的项目将失败
只要检测到需要中断,就可以通过定义属性
myBreakProperty
来获得类似中断的内容
<for list="a,b,c,d,e" param="letter" keepgoing="true">
<sequential>
<if>
<equals arg1="@{letter}" arg2="c" />
<then>
<property name="myBreakProperty" value="nevermind the value"/>
</then>
</if>
<fail if="myBreakProperty"/>
<echo>Letter @{letter}</echo>
</sequential>
</for>
输出将是:
字母a字母b字母d字母e
您可以在不运行像失败这样苛刻的操作的情况下创建中断流程。使用属性来检测何时要中断,可以实现如下操作:
<var name="break.flag" unset="true"/>
<for list="a,b,c,d,e" param="letter">
<sequential>
<if>
<not>
<isset property="break.flag"/>
</not>
<then>
<if>
<equals arg1="@{letter}" arg2="c" />
<then>
<property name="break.flag" value="true"/>
</then>
</if>
<if>
<not>
<isset property="break.flag"/>
</not>
<then>
<echo>Letter @{letter}</echo>
<echo>Do the rest of the loop here</echo>
</then>
</if>
</then>
</if>
</sequential>
</for>
字母{字母}
在这里完成循环的其余部分
要真正打破循环,可以将fail与trycatch一起使用
<trycatch>
<try>
<for param="i" begin="1" end="99">
<sequential>
...
<fail message="break" />
</sequential>
</for>
</try>
<catch />
</trycatch>
...
您的代码不起作用,如果它命中,您需要取消设置标志
<trycatch>
<try>
<for param="i" begin="1" end="99">
<sequential>
...
<fail message="break" />
</sequential>
</for>
</try>
<catch />
</trycatch>