Swift

//: 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

  

原文地址:https://www.cnblogs.com/Rinpe/p/5050809.html