List<Integer> input = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Integer sum = 0 // mutating sum
def i = 0 // iterator set to starting position of collection
def max = input.size() // calculate end position once
while (i < max) { // test if continue looping
def val = input[i]; // get value from array
sum += val; // change state of the sum
i++; // increment iterator
}
println "result of while() sum = ${sum}"