Computer/Apple Ecosystem Insights
[Swift] 반복문 !
생각하는달팽이
2016. 2. 10. 15:21
반복문을 빼놓을 수 없겠죠?
// 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)
}
반응형