- 작업 환경

 

https://growingsaja.tistory.com/771

Playground : ContentView.swift 파일 수정

 

 

 

 

 

1. for문 예제

 

var name_list: [String] = ["kim", "lee", "lim", "song", "moon"]

for stat in name_list {
    print("My name is \(stat)")
}

name_list.popLast()

for stat in name_list {
    print("Your name is \(stat)")
}

for i in 3...5 {
    print(i)
}

// 13 이상 19 미만을 2 간격으로 출력
for i in stride(from: 13, to: 19, by: 2) {
    print(i)
}

 

 

 

 

 

2. while문 예제

 

var name_list: [String] = ["kim", "lee", "lim", "song", "moon"]


var i: Int = 0

while i < 3 {
    print(name_list[i])
    i += 1
}

i = 0
while i < 5 {
    print(i)
    i += 1
}

 

 

+ Recent posts