Kotlin - Loops and RangesYou want to print all even numbers from 2 to 10 using a range. Which Kotlin code correctly does this?Afor (i in 2..10 step 2) { println(i) }Bfor (i in 2..10 step 3) { println(i) }Cfor (i in 1..10 step 2) { println(i) }Dfor (i in 2 until 10) { if (i % 2 == 0) println(i) }Check Answer
Step-by-Step SolutionSolution:Step 1: Identify even numbers from 2 to 10Even numbers are 2, 4, 6, 8, 10.Step 2: Use step 2 to iterate over evensStarting at 2 and stepping by 2 prints all even numbers up to 10.Final Answer:for (i in 2..10 step 2) { println(i) } -> Option AQuick Check:Step 2 from 2 prints evens [OK]Quick Trick: Use step 2 to iterate over even numbers [OK]Common Mistakes:MISTAKESUsing wrong step valueStarting from 1 instead of 2Using until excludes 10
Master "Loops and Ranges" in Kotlin9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kotlin Quizzes Data Types - Why Kotlin has no primitive types at source level - Quiz 7medium Data Types - Any type as universal base - Quiz 3easy Functions - Why functions are first-class in Kotlin - Quiz 12easy Functions - Local functions (nested functions) - Quiz 12easy Functions - Why functions are first-class in Kotlin - Quiz 9hard Kotlin Basics and JVM Runtime - Main function as entry point - Quiz 13medium Kotlin Basics and JVM Runtime - Print and println output - Quiz 7medium Loops and Ranges - Repeat function for simple repetition - Quiz 14medium Null Safety - Null safety in collections - Quiz 3easy Variables and Type System - Type inference by the compiler - Quiz 4medium