
This lecture is a basic explanation of what a while loop is.
This lecture explains the variations between the structural variations in while loops.
This lecture explains an example of an entry-controlled while loop.
This lecture explain a repeat-while loop
An infinite loop is a loop whose condition always evaluates to true — like while true. That means the loop has no natural exit through its condition.
To exit an infinite loop, you must use a manual escape mechanism:
break – exits the loop immediately.
return – exits the loop (and often the enclosing function).
continue – skips to the next iteration, but doesn’t exit.
Why Use Infinite Loops?
Infinite loops are useful when:
You don’t know in advance when the loop should stop.
You want full control over the exit logic inside the loop body.
You’re waiting for a condition that’s determined at runtime, like:
User input
Data stream
Hardware signals
Event polling
This lecture gives an example of a while loop with multiple conditions.
This lecture explains when to use this type of 'while' loop.
Coding Challenge: Countdown Alarm
Objective:
Write a Swift function that simulates a countdown alarm. It should:
Take a starting time in seconds.
Count down to zero.
Use a while loop to print the time remaining only while the value is greater than 0.
After the loop ends, print "Alarm triggered!".
This is a more sophisticated explanation of a while loop.
This lecture explains state tracking because it will apply to the next lecture.
This lecture explains the energy drain simulator coding challenge.
This lecture explains using a while loop to find the longest consecutive streak of identical numbers in an array.
This lecture explains how you can take the digits from an integer and reduce them to a single integer. For example: 462 = 4 + 6 + 2 = 12 = 1 + 2 = 3.
This lecture addresses finding the first repeating character in a string.
This lecture explains using a while loop to remove consecutive identical characters.
This lecture explains run-length encoding and how to decode using a while loop.
This lecture explains the use of 2 pointers to find the longest substring of non-repeating characters.
This lecture deals with using pointers to find the pair of integers that when added together create a target sum.
This lecture explain moving 0 to the end, while doing it in place.
This lecture focuses on using pointers to partition an array, separating odds from even integers.
This lecture addresses finding the position of an inserted value in an array.
This lecture explains how to find a peak in an array. This is assuming that there is a certain structure and that there is a 'mountain' in you array.
This lecture explains how to find the longest subarray of '1's in an array of integers.
In this lecture we discuss how to find the longest series of identical characters displayed consecutively.
Most Swift courses teach for loops well enough — iterating over arrays, using ranges, and walking through collections. But when it comes to while and repeat-while loops, they’re often treated as leftovers: briefly introduced, rarely practiced, and almost never applied to real-world programming problems.
This course is here to fix that.
“Drive Complex Logic with while loops” is built for software engineers who already know the basics of Swift but want to master control flow that depends on state, not structure. In other words, you’ll learn how to drive your program forward based on conditions, not collections — a critical distinction when building anything from stream processors to user input loops, algorithmic systems, or reactive app logic.
In this course, you’ll go deep into:
Entry-controlled (while) vs exit-controlled (repeat-while) loops — how they differ, when to use each, and why it matters
Building logic around state transitions rather than loop bounds
Implementing patterns like infinite loops with breaks, pointer traversal, sliding windows, and search patterns
Replacing or avoiding recursion using while-based iteration
Loop-driven simulations and condition-based algorithms
Comparing while vs for in real code — so you don’t reach for the wrong tool
Along the way, you'll solve dozens of short coding challenges designed specifically to exercise conditional looping. These aren’t filler exercises — they model the kind of edge-sensitive, state-dependent, or exit-controlled logic real engineers write in real projects.
This course assumes you already understand basic Swift syntax and have written simple functions, loops, and conditionals. If you've built simple apps or worked through a beginner Swift tutorial, you’re ready.
By the end, you'll not only understand how while loops work — you'll know why they exist, when to use them, and how to structure your code around them in ways that make your logic more expressive, readable, and powerful.
If you’ve ever written a for loop where it felt like you were forcing it to do something unnatural — this course is for you.