how to break or continue in MVEL for / foreach loop

你离开我真会死。 提交于 2019-12-10 14:46:19

问题


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


回答1:


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

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

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'.



来源:https://stackoverflow.com/questions/15262152/how-to-break-or-continue-in-mvel-for-foreach-loop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!