5-Day Swift Coding Challenge: Day 2

Apr 22 2025 · Swift 6.0, iOS 18, Swift Playground 4.6

Lesson 01: Day 2: Exploring Control Flow

Demo: Loops & Arrays

Episode complete

Play next episode

Next

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

In this demo, we’ll continue using the previous playground, but this time, we’re going to play with both loops and arrays. You saw the while loop. Let’s put this in practice. Add the following:

var sum = 1

while sum < 1000 {
  sum = sum + (sum + 1)
}
print(sum)
var sum = 1
var iterations = 0

while sum < 1000 {
  sum = sum + (sum + 1)
  iterations = iterations + 1
}
print(sum)
print(iterations)
for i in 1...3 {
  print(i)
}
var animals = [ "🐕", "🐁", "🐄" ]
var animals: [String] = [ "🐕", "🐁", "🐄" ]
animals.append(1)
animals.append("🐓")
animals[0]
animals.first
animals.last
animals.count
for i in 0...animals.count {
  print(animals[i])
}
for i in 0...animals.count - 1 {
  print(animals[i])
}
for animal in animals {
  print(animal)
}
See forum comments
Cinema mode Download course materials from Github
Previous: Loops & Arrays Next: Using Dictionaries