Swift - LoopsWhat does a while loop do in Swift?ARepeats code while a condition is trueBRuns code only onceCRuns code a fixed number of timesDStops the program immediatelyCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand the purpose of a while loopA while loop runs repeatedly as long as its condition stays true.Step 2: Compare options with the definitionOnly Repeats code while a condition is true correctly describes repeating code while a condition is true.Final Answer:Repeats code while a condition is true -> Option AQuick Check:While loop = repeat while true condition [OK]Quick Trick: While loops run as long as condition is true [OK]Common Mistakes:Thinking while loops run a fixed number of timesConfusing while with if statementsAssuming while loops run only once
Master "Loops" in Swift9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Swift Quizzes Collections - Array iteration and enumerated - Quiz 9hard Collections - Array iteration and enumerated - Quiz 11easy Control Flow - Why Swift has no implicit fallthrough - Quiz 11easy Control Flow - Why Swift has no implicit fallthrough - Quiz 6medium Loops - Repeat-while loop - Quiz 7medium Loops - Why Swift loops are safe by default - Quiz 4medium Operators and Expressions - Logical operators - Quiz 3easy Operators and Expressions - Operator overloading concept - Quiz 2easy Operators and Expressions - Logical operators - Quiz 6medium Variables and Constants - Var for variables (mutable) - Quiz 14medium