Bird
0
0

Which of the following is the correct syntax to label a loop named 'outerLoop' in Swift?

easy📝 Syntax Q12 of 15
Swift - Loops
Which of the following is the correct syntax to label a loop named 'outerLoop' in Swift?
Afor outerLoop in 1...3 { }
BouterLoop: for i in 1...3 { }
Cfor i in 1...3 outerLoop: { }
Dlabel outerLoop for i in 1...3 { }
Step-by-Step Solution
Solution:
  1. Step 1: Recall label syntax in Swift

    Labels are written as a name followed by a colon before the loop statement.
  2. Step 2: Match syntax to options

    outerLoop: for i in 1...3 { } correctly places 'outerLoop:' before the for loop.
  3. Final Answer:

    outerLoop: for i in 1...3 { } -> Option B
  4. Quick Check:

    Label name + colon before loop = A [OK]
Quick Trick: Label name ends with colon before loop starts [OK]
Common Mistakes:
  • Placing label after the loop
  • Using 'label' keyword (not valid)
  • Putting label inside loop braces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes