For loop with step and downTo in Kotlin
📖 Scenario: You are organizing a countdown event and want to display numbers counting down with a specific step.
🎯 Goal: Build a Kotlin program that counts down from 10 to 1, stepping by 2, and prints each number.
📋 What You'll Learn
Create a variable called
start with the value 10Create a variable called
end with the value 1Use a
for loop with downTo and step to count down from start to end by 2Print each number inside the loop
💡 Why This Matters
🌍 Real World
Counting down with steps is useful in timers, animations, and game loops where you want to skip certain numbers.
💼 Career
Understanding loops with steps and counting down is important for writing efficient code in many programming jobs, including app development and automation.
Progress0 / 4 steps