// 가장 기본적인 1부터 10까지의 합
var sum = 0
for counter in 1 ... 10 {
sum += counter
}
print(sum) ------- 결과 = 55
// 짝수만 나열하기
for evenNumbers in stride(from: 2, to: 11, by: 2) {
print(evenNumbers)
} --------- 결과 = 2, 4, 6, 8, 10
// 구구단 만들어보기
for i in 2...9 { ----------2단부터 9단 까지
for j in 1...9 { ----------i 를 곱하기 1부터 9까지
print(\(i) X \(j) = \(i * j)
}
}
이렇게 하면 2단부터 9단까지 싸그리 다 출력 오케이
'ios Development > Swift' 카테고리의 다른 글
syntax optimization 스위프트 문법 최적화 closure (0) | 2020.01.08 |
---|---|
while 반복문의 두가지 (0) | 2020.01.04 |
Type Alias (0) | 2020.01.02 |
Type safety (0) | 2020.01.02 |
Type annotation (0) | 2020.01.02 |