Published in: Groovy
URL: http://hansamann.podspot.de/files/grails_podcast_episode_40.mp3
This snippet gives you some interesting examples about Groovy Control Structures. Listen to the audio to get the best learning experience. Simply right-click on the title above to download the mp3 file of this part of the series.
The Groovy Series is part of the Grails Podcast and can be subscribed to via: http://hansamann.podspot.de/rss. The series is produced by Dierk König and Sven Haiges, further information about the topic of this episode can be found in the book
Groovy in Action - http://groovy.canoo.com/gina
//if / else if / else def x = 1 //conditional ?: assert txt == 'true' //powerful switch statement, isCase() :-) def someValue = 5 def feedback = '' default: feedback = 'unknown' } //java.lang.Class contains an isCase() method, we can classify by class someValue = 5.5 feedback = '' default: feedback = 'You are using an unknown number type!' } //switching on Lists someValue = 4 feedback = '' } //matcher with switch someValue = 'Hello World' feedback = '' } //for //pretty standard java5 for loop in groovy def result = '' result += item } //using ranges in for loops result << character } //using for with a matcher def text = 'Get up at 8:00, have coffee at 8:15 and go to work around 11:00' //classic for loops will come with groovy 1.1 :-)
You need to login to post a comment.
