Back to questions
JuniorTheoryCommon
What does the program print?
var count = 0
outer: for _ in 1...3 {
for j in 1...3 {
if j == 3 {
break outer
}
count += 1
}
}
print(count)2
- Expecting
6: thinkingbreakalways ends only the innermost loop. With a label,break outerends the outer loop too, so there is no second outer pass. - Expecting
3: thinkingbreaklets the current pass finish. It acts at once, socount += 1below it does not run whenjis3.
- What does the program print if
break outeris replaced with a plainbreak? - What would
continue outerdo in the same place?