diff --git a/Swift/Iteration.playground/Pages/Break.xcplaygroundpage/Contents.swift b/Swift/Iteration.playground/Pages/Break.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..b3899b2 --- /dev/null +++ b/Swift/Iteration.playground/Pages/Break.xcplaygroundpage/Contents.swift @@ -0,0 +1,14 @@ +//: [For-in](@previous) + +let flag = true + +while (true) { + print("Hello") + if flag { break } + print("World") +} + +print("There") + + +//: [Continue](@next) diff --git a/Swift/Iteration.playground/Pages/Continue.xcplaygroundpage/Contents.swift b/Swift/Iteration.playground/Pages/Continue.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..e06d8ed --- /dev/null +++ b/Swift/Iteration.playground/Pages/Continue.xcplaygroundpage/Contents.swift @@ -0,0 +1,11 @@ +//: [Break](@previous) + +var i = 0 +while (i < 10) { + i += 1 + print("Hello") + if i == 5 { continue } + print("World") +} + +//: [forEach](@next) diff --git a/Swift/Iteration.playground/Pages/enumerated.xcplaygroundpage/Contents.swift b/Swift/Iteration.playground/Pages/enumerated.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..f0da4b8 --- /dev/null +++ b/Swift/Iteration.playground/Pages/enumerated.xcplaygroundpage/Contents.swift @@ -0,0 +1,11 @@ +//: [Repeat-While](@previous) + +//: offset - index of element +let arr = [7, 10, 1, 5, 2] + +for i in arr.enumerated() { + print(i.offset, i.element) +} + + +//: [For-in](@next) diff --git a/Swift/Iteration.playground/Pages/for-in.xcplaygroundpage/Contents.swift b/Swift/Iteration.playground/Pages/for-in.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..4f359b8 --- /dev/null +++ b/Swift/Iteration.playground/Pages/for-in.xcplaygroundpage/Contents.swift @@ -0,0 +1,8 @@ +//: [Enumerated](@previous) + +let arr = [7, 10, 1, 5, 2] +for i in arr { + print(i) +} + +//: [Break](@next) diff --git a/Swift/Iteration.playground/Pages/for.xcplaygroundpage/Contents.swift b/Swift/Iteration.playground/Pages/for.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..404f194 --- /dev/null +++ b/Swift/Iteration.playground/Pages/for.xcplaygroundpage/Contents.swift @@ -0,0 +1,8 @@ +//: stride(from:to:by:) iterating over collection. C-style loop has been removed +for i in stride(from: 0, to: 10, by: 1) { + print(i) +} + + + +//: [While](@next) diff --git a/Swift/Iteration.playground/Pages/forEach.xcplaygroundpage/Contents.swift b/Swift/Iteration.playground/Pages/forEach.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..741e3e8 --- /dev/null +++ b/Swift/Iteration.playground/Pages/forEach.xcplaygroundpage/Contents.swift @@ -0,0 +1,18 @@ +//: [Continue](@previous) + +let a = [7, 10, 1, 5, 2] + +a.forEach { x in + print (x) +} + +a.forEach { + print($0) +} + +[7,10,1,5].forEach { + print($0) +} + + +//: [Map](@next) diff --git a/Swift/Iteration.playground/Pages/map.xcplaygroundpage/Contents.swift b/Swift/Iteration.playground/Pages/map.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..ac91aaf --- /dev/null +++ b/Swift/Iteration.playground/Pages/map.xcplaygroundpage/Contents.swift @@ -0,0 +1,11 @@ +//: [ForEach](@previous) + +let a = [7, 10, 1, 5, 2] + +a.map { + $0 * 2 +} + +a.map { x in + x * 2 +} diff --git a/Swift/Iteration.playground/Pages/repeat-while.xcplaygroundpage/Contents.swift b/Swift/Iteration.playground/Pages/repeat-while.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..ce954e0 --- /dev/null +++ b/Swift/Iteration.playground/Pages/repeat-while.xcplaygroundpage/Contents.swift @@ -0,0 +1,11 @@ +//: [While](@previous) + +//: Note: Do-While has been removed. Repeat-While instead. +var i = 0 +repeat { + i += 1 + print(i) +} while(i < 10) + + +//: [Enumerated](@next) diff --git a/Swift/Iteration.playground/Pages/while.xcplaygroundpage/Contents.swift b/Swift/Iteration.playground/Pages/while.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..8abe011 --- /dev/null +++ b/Swift/Iteration.playground/Pages/while.xcplaygroundpage/Contents.swift @@ -0,0 +1,10 @@ +//: [For](@previous) +var a = 0 +while (a < 10) { + a += 1 + print(a) +} +//: [Repeat-While](@next) + + + diff --git a/Swift/Iteration.playground/contents.xcplayground b/Swift/Iteration.playground/contents.xcplayground new file mode 100644 index 0000000..824ec47 --- /dev/null +++ b/Swift/Iteration.playground/contents.xcplayground @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Swift/Iteration.playground/playground.xcworkspace/contents.xcworkspacedata b/Swift/Iteration.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/Swift/Iteration.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Swift/Iteration.playground/playground.xcworkspace/xcuserdata/Askrav.xcuserdatad/UserInterfaceState.xcuserstate b/Swift/Iteration.playground/playground.xcworkspace/xcuserdata/Askrav.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..5370cb2 Binary files /dev/null and b/Swift/Iteration.playground/playground.xcworkspace/xcuserdata/Askrav.xcuserdatad/UserInterfaceState.xcuserstate differ