有没有办法打破速度的 foreach 循环? [英] Is there a way to break from a foreach loop in velocity?
本文介绍了有没有办法打破速度的 foreach 循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在通过使用 foreach 遍历(权限)集合来寻找特定条件.所以如果我找到了我需要的所有东西并且不再需要循环,有没有办法跳出循环?我是速度的新手,并试图理解这种奇怪的语言.
I'm looking for a certain condition by using foreach to iterate through a collection (of permissions). So if I find all that I need and don't need to loop anymore, is there a way to break out of the loop? I am new to velocity and trying to grok this weird language.
#foreach ($perm in $space.getPermissions())
#end
推荐答案
最新版本的 Velocity (1.6) 包含一个声明 #break
The latest version of Velocity (1.6) contains a statement #break
https://velocity.apache.org/engine/1.6.2/user-guide.html#Loops
## list first 5 customers only
#foreach( $customer in $customerList )
#if( $velocityCount > 5 )
#break
#end
$customer.Name
#end
这篇关于有没有办法打破速度的 foreach 循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文