Counting Down with a While Loop
📖 Scenario: Imagine you have a rocket that needs to count down before launch. You want to create a simple program that counts down from a number to zero.
🎯 Goal: Build a Swift program that uses a while loop to count down from 5 to 0 and print each number.
📋 What You'll Learn
Create a variable called
count with the value 5Create a variable called
zero with the value 0Use a
while loop that runs as long as count is greater than or equal to zeroInside the loop, print the current value of
countInside the loop, decrease
count by 1 each time💡 Why This Matters
🌍 Real World
Counting down is used in many real-world situations like rocket launches, game timers, or cooking timers.
💼 Career
Understanding loops is essential for programming tasks that require repetition, such as processing data, animations, or user interactions.
Progress0 / 4 steps