Bird
0
0

Which of the following best describes a while loop in Swift?

easy📝 Conceptual Q2 of 15
Swift - Loops
Which of the following best describes a while loop in Swift?
AExecutes code only if condition is false
BExecutes code repeatedly while a condition is true
CExecutes code a fixed number of times
DExecutes code once before checking condition
Step-by-Step Solution
Solution:
  1. Step 1: Recall the purpose of a while loop

    A while loop runs repeatedly as long as its condition remains true.
  2. Step 2: Compare options to this behavior

    Only Executes code repeatedly while a condition is true correctly states this behavior.
  3. Final Answer:

    Executes code repeatedly while a condition is true -> Option B
  4. Quick Check:

    While loop repeats while condition true = Executes code repeatedly while a condition is true [OK]
Quick Trick: While loops repeat only if condition is true [OK]
Common Mistakes:
  • Confusing with repeat-while loops
  • Thinking it runs a fixed number of times

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes