Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Instruction count comparison
@differentiable
func nested_loop(_ x: Float, count: Int) -> Float {
var outer = x
outerLoop: for _ in 1..<count {
outer = outer * x
var inner = outer
var i = 1
while i < count {
inner = inner + x
i += 1
switch Int(inner.truncatingRemainder(dividingBy: 7)) {
case 0: break outerLoop
case 1: break
default: continue
}
}
outer = inner
}
return outer
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment