Bird
0
0

Which of the following is the correct syntax to label a loop named myLoop in Kotlin?

easy📝 Syntax Q3 of 15
Kotlin - Loops and Ranges
Which 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) { }
Step-by-Step Solution
Solution:
  1. Step 1: Understand Kotlin loop label syntax

    Labels are placed before the loop with a colon, like labelName: for(...)
  2. Step 2: Identify correct label placement

    myLoop: for (i in 1..5) { } correctly places myLoop: before the for loop.
  3. Final Answer:

    myLoop: for (i in 1..5) { } -> Option D
  4. Quick Check:

    Loop label syntax = label: for(...) [OK]
Quick Trick: Place label before loop with colon: label: for(...) [OK]
Common Mistakes:
MISTAKES
  • Placing label inside loop body
  • Using label after for keyword
  • Using parentheses incorrectly with label

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes