Swift - LoopsHow 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 { }Check Answer
Step-by-Step SolutionSolution:Step 1: Understand Swift label syntaxLabels are placed before the loop statement followed by a colon.Step 2: Identify correct placementThe label 'mainLoop' should be immediately before the 'for' keyword with a colon.Final Answer:mainLoop: for i in 1...5 { } -> Option AQuick 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 keywordUsing 'label' keyword which doesn't exist in SwiftPutting label inside the loop braces
Master "Loops" in Swift9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Swift Quizzes Collections - Array operations (append, insert, remove) - Quiz 8hard Collections - Dictionary creation and access - Quiz 2easy Functions - Variadic parameters - Quiz 6medium Functions - Argument labels and parameter names - Quiz 12easy Loops - Break and continue behavior - Quiz 6medium Loops - For-in with where clause - Quiz 2easy Operators and Expressions - Why operator safety matters in Swift - Quiz 2easy Optionals - Nil coalescing operator (??) - Quiz 3easy Swift Basics and Runtime - What is Swift - Quiz 11easy Variables and Constants - Type aliases for readability - Quiz 6medium