Threading While Loops into Closures in Swift
// multiplies by adding using a while loop within a closure
var MulbyAdding = {(x:Int, y:Int) -> Int in var add = 0; var count = 0; while count < y {
add += x
count += 1
}; return add
}
// A Power closure that uses MulbyAdding and a while loop
var PowerbyMul = {(x:Int, y:Int) -> Int in var Pow = x; var count = 0; while count < y {
Pow *= x; count += 1
}; return Pow
}