[Swift] 반복문 !

2016. 2. 10. 15:21Computer/Apple Ecosystem Insights


반복문을 빼놓을 수 없겠죠?



// for and while loops


// for loop

var names = ["apple","banna","cherry","dole","fineapple","goody","honey"]

for var x=0;x<names.count;x++ {

    print("name is \(names[x]).")

}


// for-in


for name in names {

    print("[forin] Name : is \(name)")

}


// while


var x = 0;

while ( x < names.count){

    print("names[\(x)] : \(names[x]) ")

    x++;

}


// do while >> change to repeat while

x = 0

repeat {

    print(x)

    x++

}while(x < 100 )



// Dictionary With loop


var states = ["NJ":"New Jersey","CA":"California"]


for (abbrev,state) in states {

    print(abbrev)

    print(state)

}



반응형

'Computer > Apple Ecosystem Insights' 카테고리의 다른 글

[Swift] Dictionary  (0) 2016.02.10
[Swift] Array  (0) 2016.02.10
[Swift] 함수  (0) 2016.02.10
[Swift] 조건문  (0) 2016.02.10
[Swift] 변수들의 타입  (2) 2016.02.05