
This lecture explains the practicality of using repeat-while loops.
This lecture explains using a repeat-while loop for validating data in an array.
This lecture explains using a 'repeat-while' loop when validating a password.
This lecture discusses converting elements in an array to integer.
We are using repeat while loop to find a cumulative sum threshold.
This lecture will walk you through calculating the sum until it is a single digit.
This lecture explains solving a problem for a coding challenge that involves creating a countdown.
This coding challenge asks us to to find elements in an array that would bring us closer to a target.
This lecture is a little more sophisticated and returns a tuple.
Problem Statement
You’re simulating a device that recharges energy in cycles, starting from a given energy level (between 0 and 100). Each recharge cycle:
Increases energy by a random amount between 5 and 15.
Adds 1 second to the recharge time.
If a recharge causes the energy to exceed 100, the device overheats and the process stops with failure.
If energy reaches exactly 100, the recharge is successful.
The process also stops with failure if more than 10 seconds pass without fully charging.
Requirements
Use a repeat-while loop to control the recharge process.
Return a result that includes:
Whether the recharge succeeded (true) or failed (false)
Final energy level
Total time elapsed in seconds
Recharge history (array of recharge amounts per second)
Coding Challenge: Mission Control: Probe Descent Simulation
Problem Statement
You’re simulating a probe’s descent onto a planetary surface. The goal is to land the probe safely without:
Running out of fuel
Crashing due to speed
Exceeding the maximum number of descent steps
Simulation Rules
The probe starts at altitude = 500 meters.
It starts with fuel = 100 units.
Each second:
The probe descends a random amount between 30 and 60 meters.
Descent consumes fuel: 1 unit per 5 meters descended (rounded up).
The probe’s speed (descent rate) is determined by the most recent descent.
The mission ends in success if the probe lands (altitude ≤ 0) and its last descent speed is ≤ 40 meters.
The mission fails if:
Fuel runs out before landing.
The probe lands but the last descent was too fast (> 40 meters).
The simulation runs for more than 10 seconds.
Requirements
Use a repeat-while loop.
Return a tuple or struct containing:
success: Bool
finalAltitude: Int (can be negative)
fuelRemaining: Int
secondsElapsed: Int
history: [(descent: Int, fuelUsed: Int)]
Final Summary
The probe lands successfully if and only if all of the following are true:
fuel >= 0
seconds <= 10
altitude <= 0
lastDescent <= 40
If any of these conditions are not met, the mission fails.
Coding Challenge: Space Station Oxygen Regulation
Problem Statement
You are simulating an oxygen control system aboard a space station. The station must maintain life-support-safe oxygen levels for a given period of time.
Simulation Rules
The station starts with oxygen level = 70 units.
The goal is to maintain oxygen at 50 to 100 units, inclusive, for 15 seconds.
Each second:
Oxygen randomly increases by 0–5 units due to natural air recycling.
Oxygen also randomly decreases by 5–15 units due to crew consumption and system leaks.
If the oxygen level falls below 50 or exceeds 100, an alert is triggered.
The station has 3 emergency restores. When triggered:
It adds +20 oxygen units immediately, but consumes one restore.
Restores are only activated automatically if oxygen would drop below 50.
Failure and Success Criteria
If the oxygen goes out of safe range (50–100) and no restores remain, the mission fails.
If the oxygen stays within range or is recovered via restores for all 15 seconds, the mission succeeds.
Requirements
Use a repeat-while loop.
Track each second’s oxygen delta and restore usage.
Return:
success: Bool
Final oxygen level
Seconds elapsed
Restores remaining
Log of changes: [(second: Int, oxygenBefore: Int, increase: Int, decrease: Int, oxygenAfter: Int, restored: Bool)]
Find First Vowel in a Word
Problem Statement
Write a Swift function that takes a string and returns the first vowel character it encounters, along with its index. If no vowel exists, return nil.
Constraints
Treat a, e, i, o, u (lowercase only) as vowels.
You must use a repeat-while loop.
Do not use for-in, forEach, or high-level iteration methods.
Problem Statement
You’re given a string consisting of digit-letter pairs where each digit (1–9) indicates how many times the following character should appear in the output.
Write a Swift function to expand the string, repeating each character according to its preceding digit.
Requirements
You must use a repeat-while loop.
Do not use for-in, forEach, or map, etc.
The input is well-formed: always an even-length string with digit-letter pairs.
Return the expanded result as a String.
Most Swift developers learn for-in and while loops early, but few ever master—or even use—repeat-while loops. This course is the only focused resource that not only teaches you how repeat-while works, but also contrasts it directly with for-in loops through hands-on coding challenges, practical simulations, and performance-minded reasoning.
Whether you're a beginner looking to understand loop types more deeply, or an experienced coder wondering when a repeat-while loop is truly the better tool, this course will teach you:
When and why repeat-while is more efficient than for-in in certain real-world scenarios.
How to use repeat-while in place of higher-overhead patterns involving enumerators or closures.
How to structure and control loops when guaranteed first execution or fine-grained iteration is critical.
What kinds of problems can be solved more clearly or safely with repeat-while logic.
We’ll walk through increasingly challenging problems that highlight where repeat-while shines—not just in theory, but in practical application. You’ll also refactor common for-in patterns to cleaner, more efficient alternatives using repeat-while.
If you're tired of loop tutorials that barely touch on repeat-while—or skip it entirely—this course gives it the attention it deserves.
By the end, you'll write smarter, more intentional Swift code with complete confidence in your control flow decisions.