Swift - LoopsWhat does the following Swift code print?for i in 1...3 { print(i) }A1 2B1 2 3C0 1 2 3D2 3 4Check Answer
Step-by-Step SolutionSolution:Step 1: Understand the range operatorThe range 1...3 is a closed range including 1, 2, and 3.Step 2: Loop prints each number in the rangeThe loop prints 1, then 2, then 3 on separate lines.Final Answer:1 2 3 -> Option BQuick Check:Closed range includes last number = 1 2 3 [OK]Quick Trick: Closed range includes last number, so count all numbers [OK]Common Mistakes:Thinking the last number is excludedStarting from 0 instead of 1Confusing closed and half-open ranges
Master "Loops" in Swift9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Swift Quizzes Control Flow - Switch statement power - Quiz 10hard Data Types - Character and String types - Quiz 13medium Data Types - Character and String types - Quiz 1easy Data Types - Type conversion is always explicit - Quiz 5medium Functions - In-out parameters for mutation - Quiz 14medium Functions - Why functions are first-class in Swift - Quiz 7medium Functions - Omitting argument labels with _ - Quiz 12easy Loops - While loop - Quiz 10hard Operators and Expressions - Range operators (... and ..<) - Quiz 12easy Operators and Expressions - Identity operators (=== and !==) - Quiz 5medium