Last active
August 29, 2015 14:05
-
-
Save k0nserv/920e2a35be9e41cd7d26 to your computer and use it in GitHub Desktop.
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
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