Kotlin - Loops and RangesHow can you use ranges to print numbers from 10 down to 5 in Kotlin?Afor (i in 10..5) { println(i) }Bfor (i in 10 downTo 5) { println(i) }Cfor (i in 5..10 step -1) { println(i) }Dfor (i in 10..5 step 1) { println(i) }Check Answer
Step-by-Step SolutionSolution:Step 1: Understand descending rangesTo count down, Kotlin uses 'downTo' instead of '..'.Step 2: Check each optionfor (i in 10 downTo 5) { println(i) } uses '10 downTo 5' which correctly counts down from 10 to 5.Final Answer:for (i in 10 downTo 5) { println(i) } -> Option BQuick Check:Use 'downTo' for descending ranges [OK]Quick Trick: Use 'downTo' for counting down in ranges [OK]Common Mistakes:MISTAKESUsing '..' for descending rangesTrying negative step in ascending rangeConfusing step direction
Master "Loops and Ranges" in Kotlin9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kotlin Quizzes Collections Fundamentals - Collection size and emptiness checks - Quiz 5medium Control Flow as Expressions - When without argument - Quiz 7medium Data Types - Char type and Unicode behavior - Quiz 3easy Loops and Ranges - Labeled break and continue - Quiz 1easy Null Safety - Let function with safe calls - Quiz 5medium Null Safety - Let function with safe calls - Quiz 4medium Null Safety - Why null safety is Kotlin's defining feature - Quiz 5medium Operators and Expressions - Equality (== structural vs === referential) - Quiz 3easy Variables and Type System - Type inference by the compiler - Quiz 3easy Variables and Type System - Why immutability by default matters - Quiz 10hard