Groovy Loops


def strings ['how','are','you']
def results []
strings.eachWithIndex s,-> results << "$i:$s" }
assert results == ["0:how","1:are","2:you"]
 
def words "I'm a Groovy coder".tokenize()
def capitalized ''
for (word in words{
    capitalized += word.capitalize(' '
}
assert capitalized == "I'm A Groovy Coder "

// traditional Java for loop
for (int 0words.size()i++{
println "$i -- ${words[i]}"
}

// traditional Java while loop
int 1000
while (1{
println x
x/2
}

Comments

Popular posts from this blog

தட்டு வண்டியில் காளிக்கோயில் - சிறுகதை

பிரேமாவின் பெண் குழந்தை

தீபம் பிளக்ஸ்