Skip to content

Instantly share code, notes, and snippets.

@rubykv
Last active March 24, 2017 19:34
Show Gist options
  • Save rubykv/b0f3c02ca7a4b634ca2a6a7a3c6d2972 to your computer and use it in GitHub Desktop.
Save rubykv/b0f3c02ca7a4b634ca2a6a7a3c6d2972 to your computer and use it in GitHub Desktop.
Basic groovy commands

##Classic Hello World println "Hello World" println "Hello World 2"

//for loop def value = { println it } 1.upto(5,value) //alternative to above for loop 1.upto(5,{ println it })

//simple each loop (1..5).each{ println "each loop output is ${it}" } //each loop on a map def sampleMap =['dog':'max','bird':'sweety'] sampleMap.each{ pet,name -> println"Our ${pet} is ${name} " }; //Alternative approach:each loop on a map def sampleMap1 =['dog':'max','bird':'sweety'] sampleMap1.each{ pet -> println"Our ${pet.key} is ${pet.value} " };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment