Bird
0
0

Which of the following is the correct syntax for a repeat-while loop in Swift?

easy📝 Syntax Q12 of 15
Swift - Loops
Which of the following is the correct syntax for a repeat-while loop in Swift?
Arepeat (condition) { /* code */ }
Brepeat { /* code */ } while condition
Cwhile condition { /* code */ } repeat
Ddo { /* code */ } while condition
Step-by-Step Solution
Solution:
  1. Step 1: Recall Swift syntax for repeat-while

    The correct syntax starts with the keyword repeat, followed by a code block in braces, then the while keyword with the condition.
  2. Step 2: Check each option

    repeat { /* code */ } while condition matches the correct syntax exactly. repeat (condition) { /* code */ } incorrectly places the condition in parentheses after repeat. while condition { /* code */ } repeat mixes while and repeat incorrectly. do { /* code */ } while condition uses do-while which is not valid Swift syntax.
  3. Final Answer:

    repeat { /* code */ } while condition -> Option B
  4. Quick Check:

    repeat { } while condition syntax [OK]
Quick Trick: Remember: repeat { } while condition is the correct form [OK]
Common Mistakes:
  • Using do-while instead of repeat-while
  • Placing condition inside parentheses after repeat
  • Mixing while and repeat keywords

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes