Swift - 22 - 循环结构

//: Playground - noun: a place where people can play

import UIKit

// for-in
for i in -99...99
{
    i * i
}

let array = ["Rinpe", "Bobo", "Lili"]
for (index, name) in array.enumerate()
{
    print("\(index), \(name)");
}

for (_, name) in array.enumerate()
{
    print("\(name)")
}

let dict = [1:"Rinpe", 2:"Bobo", 3:"Lili"]
for (key, value) in dict {
    print("\(key) - \(value)")
}

// for

for var i = 0; i <= 100; i++
{
    i * i
}

// while

var i = 100;
while i > 0     // 符合这个条件才循环下去
{
    i--
}

// do-while(无论条件是否符合, 都会执行一次)
i = 100
repeat
{
    i--
} while i == 100

i

  

posted @ 2015-12-16 12:39  Rinpe  阅读(164)  评论(0编辑  收藏  举报