Last active
August 29, 2015 14:25
-
-
Save jweinst1/d25336947712b4f1e930 to your computer and use it in GitHub Desktop.
Threading While Loops into Closures in Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment