Kotlin - Loops and RangesWhich of the following is the correct syntax for a Kotlin for loop that prints numbers 1 to 3?Afor (i in 1..3) println(i)Bfor (i = 1; i <= 3; i++) println(i)Cfor i in 1..3 { println(i) }Dfor i = 1 to 3 { println(i) }Check Answer
Step-by-Step SolutionSolution:Step 1: Recall Kotlin for loop syntaxKotlin requires parentheses around the loop variable and range: for (i in 1..3).Step 2: Check each optionfor (i in 1..3) println(i) matches correct syntax. A misses parentheses, B uses Java-style syntax, D uses invalid syntax.Final Answer:for (i in 1..3) println(i) -> Option AQuick Check:Kotlin for loop needs parentheses and 'in' keyword = C [OK]Quick Trick: Kotlin for loops use 'for (var in range)' syntax [OK]Common Mistakes:MISTAKESOmitting parentheses around loop variableUsing Java-style for loop syntaxUsing 'to' instead of '..' for ranges
Master "Loops and Ranges" in Kotlin9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kotlin Quizzes Control Flow as Expressions - When expression as powerful switch - Quiz 15hard Kotlin Basics and JVM Runtime - Why Kotlin over Java - Quiz 8hard Loops and Ranges - Labeled break and continue - Quiz 5medium Loops and Ranges - For loop with step and downTo - Quiz 15hard Null Safety - Safe call operator (?.) - Quiz 12easy Null Safety - Safe call operator (?.) - Quiz 2easy Null Safety - Nullable types with ? suffix - Quiz 2easy Operators and Expressions - Range operator (..) and in operator - Quiz 13medium Variables and Type System - Var for mutable references - Quiz 12easy Variables and Type System - Var for mutable references - Quiz 4medium