Probably you use JEXL expression instead of script.
You can use only Ternary conditional in expression.
if-else, return, for, while should be used in script:
JexlEngine jexl = new JexlBuilder().create();
JexlScript script = jexl.createScript(scriptText);
result = script.execute(context);
See http://commons.apache.org/proper/commons-jexl/reference/syntax.html
From javadoc:
An expression is different than a script - it is simply a reference to a single expression, not to multiple statements.
This implies 'if','for','while','var' and blocks '{'... '}'are NOT allowed in expressions.
A script is some valid JEXL syntax to be executed with a given set of JexlContext variables.
A script is a group of statements, separated by semicolons.
The statements can be blocks (curly braces containing code), Control statements such as if and while as well as expressions and assignment statements.