swift 循环 for while

前端之家收集整理的这篇文章主要介绍了swift 循环 for while前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

循环语句


//  main.swift
//  L001for
//
//  Created by hins on 16/10/26.
//  Copyright © 2016年 hins. All rights reserved.
//

import Foundation

print("Hello,World!")

//循环

//数组循环
var arr:[Int] = Array();

for item in 1...100{
    arr.append(item);
    //print("=======")
}
print(arr.count)

for (i,value) in EnumerateSequence(arr){
    print("\(i+1)======\(value)");
    
}

var n=0;
while n<arr.count{
    print("\(n),\(arr[n])");
    n = n+1;
}

//字典循环
var dict:Dictionary<Int,String> = Dictionary();

for i in 1...10{
    dict[i]="aaa\(i)";
}

for (key,value) in dict{
    print("\(key),\(value)");
}
原文链接:https://www.f2er.com/swift/322768.html

猜你在找的Swift相关文章