Programming in Swift: Fundamentals

Oct 19 2021 Swift 5.5, iOS 15, Xcode 13

Part 3: Control Flow

18. While Loops

Lesson Complete

Play Next Lesson
Next
Save for later
About this episode
See versions

See forum comments
Cinema mode Mark as Complete Download course materials
Previous episode: 17. Introduction Next episode: 19. Challenge: While Loops

Update Notes: The student materials have been reviewed and are updated as of October 2021.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.

What if you had to write some Swift code to print out a string 100 times? It would be tedious to write 100 print statements, but it would also violate the “Don’t Repeat Yourself” rule 99 times.

var i = 1
while i < 10
while i < 10 {

}
while i < 10 {
  print(i)
}
while i < 10 {
  print(i)
  i += 1
}
print("Counting up again")
i = 1
repeat {

}
repeat {
  print(i)
  i += 1
} 
var i = 10

i = 10