Completed 100 Days of Swift - Day #4
This commit is contained in:
parent
350de9bc52
commit
3f490023fa
|
@ -11,5 +11,5 @@
|
|||
- **[Conditions](/100DaysOfSwift/Day3/Conditions.swift)**
|
||||
- **[Combining conditions](/100DaysOfSwift/Day3/Combining%20conditions.swift)**
|
||||
- **[The ternary operator](/100DaysOfSwift/Day3/The%20ternary%20operator.swift)**
|
||||
- \*\*[Switch statements](/100DaysOfSwift/Day3/Switch%20statements.swift)
|
||||
- **[Switch statements](/100DaysOfSwift/Day3/Switch%20statements.swift)**
|
||||
- **[Range operators](/100DaysOfSwift/Day3/Range%20operators.swift)**
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
// Exiting Loops
|
||||
// https://www.hackingwithswift.com/sixty/4/4/exiting-loops
|
||||
|
||||
var countDown = 10
|
||||
|
||||
while countDown >= 0 {
|
||||
print(countDown)
|
||||
countDown -= 1
|
||||
}
|
||||
|
||||
print("Blast off!")
|
||||
|
||||
//
|
||||
|
||||
while countDown >= 0 {
|
||||
print(countDown)
|
||||
|
||||
if countDown == 4 {
|
||||
print("I'm bored. Let's go now!")
|
||||
break
|
||||
}
|
||||
|
||||
countDown -= 1
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
// Exiting multiple loops
|
||||
// https://www.hackingwithswift.com/sixty/4/5/exiting-multiple-loops
|
||||
|
||||
for i in 1...10 {
|
||||
for j in 1...10 {
|
||||
let product = i * j
|
||||
print ("\(i) * \(j) is \(product)")
|
||||
}
|
||||
}
|
||||
|
||||
outerLoop: for i in 1...10 {
|
||||
for j in 1...10 {
|
||||
let product = i * j
|
||||
print ("\(i) * \(j) is \(product)")
|
||||
}
|
||||
}
|
||||
|
||||
outerLoop: for i in 1...10 {
|
||||
for j in 1...10 {
|
||||
let product = i * j
|
||||
print ("\(i) * \(j) is \(product)")
|
||||
|
||||
if product == 50 {
|
||||
print("It's a bullseye!")
|
||||
break outerLoop
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
// For Loops
|
||||
// https://www.hackingwithswift.com/sixty/4/1/for-loops
|
||||
|
||||
let count = 1...10
|
||||
|
||||
for number in count {
|
||||
print("Number is \(number)")
|
||||
}
|
||||
|
||||
let albums = ["Red", "1989", "Reputation"]
|
||||
|
||||
for album in albums {
|
||||
print("\(album) is on Apple Music")
|
||||
}
|
||||
|
||||
print("Players gonna ")
|
||||
|
||||
for _ in 1...5 {
|
||||
print("play")
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
// Infinite loops
|
||||
// https://www.hackingwithswift.com/sixty/4/7/infinite-loops
|
||||
|
||||
var counter = 0
|
||||
|
||||
while true {
|
||||
print(" ")
|
||||
counter += 1
|
||||
|
||||
if counter == 273 {
|
||||
break
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
# Day #4
|
||||
|
||||
---
|
||||
|
||||
**What I learned about**
|
||||
|
||||
- **[For loops](/100DaysOfSwift/Day4/For%20loops.swift)**
|
||||
- **[While loops](/100DaysOfSwift/Day4/While%20loops.swift)**
|
||||
- **[Repeat loops](/100DaysOfSwift/Day4/Repeat%20loops.swift)**
|
||||
- **[Exiting loops](/100DaysOfSwift/Day4/Exiting%20loops.swift)**
|
||||
- **[Exiting multiple loops](/100DaysOfSwift/Day4/Exiting%20multiple%20loops.swift)**
|
||||
- **[Skipping items](/100DaysOfSwift/Day4/Skipping%20items.swift)**
|
||||
- **[Infinite loops](/100DaysOfSwift/Day4/Infinite%20loops.swift)**
|
|
@ -0,0 +1,19 @@
|
|||
// Repeat Loops
|
||||
// https://www.hackingwithswift.com/sixty/4/3/repeat-loops
|
||||
|
||||
var number = 1
|
||||
|
||||
repeat {
|
||||
print(number)
|
||||
number += 1
|
||||
} while number <= 20
|
||||
|
||||
print("Ready or not, here I come!")
|
||||
|
||||
while false {
|
||||
print("This is false")
|
||||
}
|
||||
|
||||
repeat {
|
||||
print("This is false")
|
||||
} while false
|
|
@ -0,0 +1,10 @@
|
|||
// Skipping items
|
||||
// https://www.hackingwithswift.com/sixty/4/6/skipping-items
|
||||
|
||||
for i in 1...10 {
|
||||
if i % 2 == 1 {
|
||||
continue
|
||||
}
|
||||
|
||||
print(i)
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
// While Loops
|
||||
// https://www.hackingwithswift.com/sixty/4/2/while-loops
|
||||
|
||||
var number = 1
|
||||
|
||||
while number <= 20 {
|
||||
print(number)
|
||||
number += 1
|
||||
}
|
||||
|
||||
print("Ready or not, here I come!")
|
|
@ -13,3 +13,4 @@
|
|||
- **[Day #1](/100DaysOfSwift/Day1/)** - variables, simple data types, and string interpolation
|
||||
- **[Day #2](/100DaysOfSwift/Day2/)** - arrays, dictionaries, sets, and enums
|
||||
- **[Day #3](/100DaysOfSwift/Day3/)** - operators and conditions
|
||||
- **[Day #4](/100DaysOfSwift/Day4/)** - loops, loops, and more loops
|
Loading…
Reference in New Issue