码迷,mamicode.com
首页 > 其他好文 > 详细

swift从0加到1000(不包括1000)的四种写法

时间:2014-06-25 15:56:28      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   color   for   

用了while, do...while, for in, for in ...

var i = 0

var temp = 0

while i < 1000 {
    
    temp += i
    
    i++
}

println(temp)

var j = 0

var temp2 = 0

do {

    temp2 += j

    j++

} while (j < 1000)

println(temp2)

var temp3 = 0

for a in 0...999 {
    
    temp3 += a
}

println(temp3)

var temp4 = 0

for var b = 0; b < 1000; b++ {
    
    temp4 += b;
}

println(temp4)

 

swift从0加到1000(不包括1000)的四种写法,布布扣,bubuko.com

swift从0加到1000(不包括1000)的四种写法

标签:style   class   blog   code   color   for   

原文地址:http://www.cnblogs.com/skiy/p/3806410.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!