|
|||||
|
|||||
Useful Things |
MVEL 2.0 Control Flow
MVEL's power goes beyond simple expressions. In fact, MVEL supports an assortment of control flow operators which will allow you to perform advanced scripting operations. If-Then-ElseMVEL supports full, C/Java-style if-then-else blocks. For example: Ternary statementsTernary statements are supported just as in Java: And nested ternary statements: ForeachOne of the most powerful features in MVEL is it's foreach operator. It is similar to the for each operator in Java 1.5 in both syntax and functionality. It accepts two parameters separated by a colon, the first is the local variable for the current element, and the second is the collection or array to be iterated. For example: Since MVEL treats Strings as iterable objects you can iterate a String (character by character) with a foreach block: The above example outputs: [A][B][C][D][E][F][G][H][I][J][K][L][M][N][O][P][Q][R][S][T][U][V][W][X][Y][Z] You can also use MVEL to count up to an integer value (from 1): Which outputs: 123456789 Syntax Note: As of MVEL 2.0, it is now possible to simply abbreviate foreach in the same way it is in Java 5.0, by using the For LoopMVEL 2.0 implements standard C for-loops: Do While, Do Until
... is semantically equivalent to ... While, UntilMVEL 2.0 implements standard ... or ... |
||||
|
Copyright 2003-2006 - The Codehaus. All rights reserved unless otherwise noted.
Powered by Atlassian Confluence
|
|||||