Bird
0
0

What does a while loop do in Swift?

easy📝 Conceptual Q11 of 15
Swift - Loops
What does a while loop do in Swift?
ARepeats code while a condition is true
BRuns code only once
CRuns code a fixed number of times
DStops the program immediately
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of a while loop

    A while loop runs repeatedly as long as its condition stays true.
  2. Step 2: Compare options with the definition

    Only Repeats code while a condition is true correctly describes repeating code while a condition is true.
  3. Final Answer:

    Repeats code while a condition is true -> Option A
  4. Quick 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 times
  • Confusing while with if statements
  • Assuming while loops run only once

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes