Bird
0
0

How do you correctly define a label named 'mainLoop' for a for-in loop in Swift?

easy📝 Syntax Q3 of 15
Swift - Loops
How do you correctly define a label named 'mainLoop' for a for-in loop in Swift?
AmainLoop: for i in 1...5 { }
Bfor mainLoop in 1...5 { }
Cfor i in 1...5 mainLoop: { }
Dlabel mainLoop for i in 1...5 { }
Step-by-Step Solution
Solution:
  1. Step 1: Understand Swift label syntax

    Labels are placed before the loop statement followed by a colon.
  2. Step 2: Identify correct placement

    The label 'mainLoop' should be immediately before the 'for' keyword with a colon.
  3. Final Answer:

    mainLoop: for i in 1...5 { } -> Option A
  4. Quick Check:

    Label followed by colon before loop [OK]
Quick Trick: Label name followed by colon before loop [OK]
Common Mistakes:
  • Placing label after the loop keyword
  • Using 'label' keyword which doesn't exist in Swift
  • Putting label inside the loop braces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes