Last active
August 29, 2015 14:02
-
-
Save trungtran/d77172ba7fdfc8dd5a5b to your computer and use it in GitHub Desktop.
Custom While Loop in Swift
This file contains 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
func customWhile(condition: (Void) -> Bool, body: (Void) -> Void) { | |
if condition() { | |
body() | |
customWhile(condition, body) | |
} | |
} | |
var number = 10 | |
customWhile({number > 0}) { | |
println("number: \(number)") | |
number-- | |
} | |
var number = 10 | |
while number > 0 { | |
println("number: \(number)") | |
number-- | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment