如何在/foreach循环的MVEL中中断或继续 [英] how to break or continue in MVEL for / foreach loop

查看:388
本文介绍了如何在/foreach循环的MVEL中中断或继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到MVEL支持循环和foreach模板,但是如何从循环中中断"或继续"呢?

I see MVEL supports for loop and foreach templating, but how to "break" or "continue" from the loop?

推荐答案

文档中未提及对"break"或"continue"的支持:

No mention of support of 'break' or 'continue' in the documentation: http://mvel.codehaus.org/MVEL+2.0+Control+Flow.

我能找到的最接近的是2009年的用户组电子邮件,其中说明不支持中断或继续: http ://markmail.org/message/rgyqvwhiedfpcchj

The closest I could find is a user group email in 2009, stating that there's NO support of break or continue: http://markmail.org/message/rgyqvwhiedfpcchj

您仍然可以通过这种方式获得与"break"相同的效果(不是世界上最干净的代码):

you could still achieve the same effect as "break" this way (not the cleanest code in the world):

skip_rest = false;
for(item: collection) {
   if (!skip_rest) {
     /* do something */
     if (some condition) {
       /* break by skipping */
       skip_rest = true; 
     }
   }
}

您知道了,可以通过标记设置来实现继续"来完成类似的事情.

You got the idea, similar thing can be done by flag setting to achieve 'continue'.

这篇关于如何在/foreach循环的MVEL中中断或继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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