Skip to content

Instantly share code, notes, and snippets.

@k0nserv
Last active August 29, 2015 14:05
Show Gist options
  • Save k0nserv/920e2a35be9e41cd7d26 to your computer and use it in GitHub Desktop.
Save k0nserv/920e2a35be9e41cd7d26 to your computer and use it in GitHub Desktop.
func _while_without_while(condition: @autoclosure () -> BooleanType,
action: () -> ()) {
var loop: () -> () = { $0 }
loop = {
// The condition is called each time to
// see if the loop should continue
if condition() {
// Then the acutal action is called
action()
// Lastly the closure calls itself recursively
loop()
}
}
// This sets off the first loop iteration
loop()
}
var j = 0
_while_without_while(j < 10) {
println("\(j)")
j += 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment