Groovy: color selector
colors = ['Blue', 'Yellow', 'Brown', 'White']
println 'Please select a number:'
colors.eachWithIndex { name, i ->
println "${i}) ${name}"
}
def selection = System.in.newReader().readLine() as Integer
if (selection < colors.size()) {
println colors[selection]
} else {
println "Bad Selection"
}
timestamp: 2018-06-02T08:30:01 tags:
- eachWithIndex
- readLine