Kotlin - Loops and RangesWhich of the following is the correct syntax to label a loop named myLoop in Kotlin?Afor (i in 1..5) { myLoop: }Bfor (i in 1..5) myLoop: { }Cfor myLoop: (i in 1..5) { }DmyLoop: for (i in 1..5) { }Check Answer
Step-by-Step SolutionSolution:Step 1: Understand Kotlin loop label syntaxLabels are placed before the loop with a colon, like labelName: for(...)Step 2: Identify correct label placementmyLoop: for (i in 1..5) { } correctly places myLoop: before the for loop.Final Answer:myLoop: for (i in 1..5) { } -> Option DQuick Check:Loop label syntax = label: for(...) [OK]Quick Trick: Place label before loop with colon: label: for(...) [OK]Common Mistakes:MISTAKESPlacing label inside loop bodyUsing label after for keywordUsing parentheses incorrectly with label
Master "Loops and Ranges" in Kotlin9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kotlin Quizzes Collections Fundamentals - Array creation and usage - Quiz 6medium Control Flow as Expressions - When with ranges and types - Quiz 8hard Control Flow as Expressions - When with ranges and types - Quiz 4medium Functions - Vararg parameters - Quiz 2easy Kotlin Basics and JVM Runtime - Why Kotlin over Java - Quiz 1easy Kotlin Basics and JVM Runtime - Print and println output - Quiz 15hard Null Safety - Platform types from Java interop - Quiz 12easy Null Safety - Non-nullable types by default - Quiz 8hard Null Safety - Safe casts with as? - Quiz 13medium Variables and Type System - Type checking with is operator - Quiz 13medium