Skip to content

Instantly share code, notes, and snippets.

@trungtran
Last active August 29, 2015 14:02
Show Gist options
  • Save trungtran/d77172ba7fdfc8dd5a5b to your computer and use it in GitHub Desktop.
Save trungtran/d77172ba7fdfc8dd5a5b to your computer and use it in GitHub Desktop.
Custom While Loop in Swift
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