func stepForward(input: Int) -> Int{
return input + 1
}
func stepBackward(input: Int) -> Int{
return input - 1
}
func chooseStepFunction(input:Bool) -> (Int) -> Int{
return input ? stepBackward : stepForward;
}
var currentValue1 : Int = 18
print(currentValue1)
while currentValue1 != 0{
let m = chooseStepFunction(input : currentValue1 > 0)
currentValue1 = m(currentValue1)
if currentValue1 != 0{
print(currentValue1,terminator: " => ")
}
else{
print(currentValue1)
}
}
print()
var currentValue2 : Int = -18
print(currentValue2)
while currentValue2 != 0{
let m = chooseStepFunction(input : currentValue2 > 0)
currentValue2 = m(currentValue2)
if currentValue2 != 0{
print(currentValue2,terminator: " => ")
}
else{
print(currentValue2)
}
}