Bird
0
0

What does the downTo keyword do in a Kotlin for loop?

easy📝 Conceptual Q11 of 15
Kotlin - Loops and Ranges
What does the downTo keyword do in a Kotlin for loop?
AIt makes the loop count forwards from a lower number to a higher number.
BIt makes the loop count backwards from a higher number to a lower number.
CIt skips numbers in the loop by a fixed step.
DIt stops the loop immediately.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of downTo

    The downTo keyword in Kotlin is used to create a range that counts backwards, from a higher number down to a lower number.
  2. Step 2: Compare with other options

    It makes the loop count forwards from a lower number to a higher number. describes counting forwards, It skips numbers in the loop by a fixed step. skipping numbers by step, and It stops the loop immediately. stopping the loop immediately, none of which downTo does.
  3. Final Answer:

    It makes the loop count backwards from a higher number to a lower number. -> Option B
  4. Quick Check:

    downTo = count backwards [OK]
Quick Trick: Remember: downTo means counting downwards [OK]
Common Mistakes:
MISTAKES
  • Confusing downTo with counting forwards
  • Thinking downTo skips numbers
  • Assuming downTo stops the loop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes