Swift 入門指南 V1.00 - 單元 6 範例




CH06.playground


var i1 = 0
var sum1 = 0
while i1 <= 10 {
    sum1 += i1
    i1++
}
println(sum1)

var i2 = 0
var sum2 = 0
do {
    sum2 += i2
    i2++
} while i2 <= 10
println(sum2)

var i3: Int
var sum3 = 0
for i3 = 0; i3 <= 10; i3++ {
    sum3 += i3
}
println(sum3)

var i4: Int
var sum4 = 0
for i4 in 0...10 {
    sum4 += i4
}
println(sum4)

the end

沒有留言: