var number: Int = 10
loop: while number > 0 {
switch number {
case 10:
var sum = 0
for index in 0...8 {
print(index)
sum += index
if index == 5 {
print(sum)
break loop
}
}
default:
break
}
}
输出结果:
0
1
2
3
4
5
15
注: 不设置标签, 通过指定标签break, 在palyground下不会跳出循环
网友评论