Bird
0
0

Which of the following is the correct syntax to loop from 10 down to 1 using a range in Kotlin?

easy📝 Syntax Q3 of 15
Kotlin - Loops and Ranges
Which of the following is the correct syntax to loop from 10 down to 1 using a range in Kotlin?
Afor (i in 10..1) { println(i) }
Bfor (i in 10 downTo 1) { println(i) }
Cfor (i in 1..10 step -1) { println(i) }
Dfor (i in 1 until 10) { println(i) }
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct descending range syntax

    Kotlin uses downTo to create a descending range.
  2. Step 2: Check options

    for (i in 10 downTo 1) { println(i) } uses 10 downTo 1, which correctly loops from 10 down to 1.
  3. Final Answer:

    for (i in 10 downTo 1) { println(i) } -> Option B
  4. Quick Check:

    Descending range uses downTo [OK]
Quick Trick: Use downTo for descending ranges [OK]
Common Mistakes:
MISTAKES
  • Using .. for descending ranges
  • Using step -1 incorrectly
  • Confusing until with downTo

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes