def results = []
(1..4).each{
def what = (it%2) ? 'odd' : 'even'
results << what
}
assert results == ['odd', 'even', 'odd', 'even']
Here, the if-condition (in (parentheses)
) is slightly more complex than just testing for existence/Groovy-Truth.