码迷,mamicode.com
首页 > 编程语言 > 详细

swift循环

时间:2015-11-17 09:29:39      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:

遍历数组
     
   var secondForLoop=0;
        for var i=0;i<3;++i{
            secondForLoop+=1;
        }
        println(secondForLoop);

for 循环遍历最大值

let interestingNumbers=[
            "prime":[3,5,3,65,33],
            "fibonacci":[1,1,5,3,3],
            "square":[1,4,2,76,43]
        ];
        var largest=0;
        for(kind,numbers)in interestingNumbers{
            for number in numbers{
            if number>largest{
                largest=number;
            }
            }
        }
        println(largest);
while循环
var n=2;
        while n<100{
            n=n*2;
        }
        println(n);

do-while循环
        var m=2;
        do{
        m=m*2;
        
        }while m<100;
        println(m);

...使用
        var firstForLoop=0;
        for i in 0...100{
            firstForLoop+=i;
        }
        println(firstForLoop);

 

 

 

 

swift循环

标签:

原文地址:http://www.cnblogs.com/hualuoshuijia/p/4970669.html

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