ant-contrib의 for/foreach 루프는 "break"또는 "continue"문과 동일한 기능을 지원합니까? 내가 말할 수있는 한, 그들은하지 않습니다.중단되었거나 계속 구현 되었습니까?
실행 가능한 해결 방법이 있습니까?
감사 -T
ant-contrib의 for/foreach 루프는 "break"또는 "continue"문과 동일한 기능을 지원합니까? 내가 말할 수있는 한, 그들은하지 않습니다.중단되었거나 계속 구현 되었습니까?
실행 가능한 해결 방법이 있습니까?
감사 -T
가이 동작을 구현하는 쉬운 방법은 없지만, 아마도 다음과 같은 제안이 도움이 될 것입니다 .
for
task (즉,하지의 foreach)를 사용fail
task를 사용 사실keepgoing
특성을 설정. Letter a Letter b
<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>
을 깰 필요가 감지 할 때마다 속성 myBreakProperty
을 정의하여 휴식 뭔가를 얻을 수 있습니다
cont와 같은 것을 얻으려면 inue :
<for list="a,b,c,d,e" param="letter" keepgoing="true">
<sequential>
<if>
<equals arg1="@{letter}" arg2="c" />
<then>
<fail/>
</then>
</if>
<echo>Letter @{letter}</echo>
</sequential>
</for>
출력은 다음과 같습니다 Letter a Letter b Letter d Letter 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>
코드가 작동하지 않습니다. 플래그가 안타를 때 플래그를 해제해야합니다. – sloven
감사합니다! 그게 효과가 있었어. –