Bird
0
0

Which of these Swift code snippets correctly uses semicolons?

easy📝 Conceptual Q2 of 15
Swift - Variables and Constants
Which of these Swift code snippets correctly uses semicolons?
Alet a = 5 let b = 10; print(a + b);
Blet a = 5 let b = 10 print(a + b)
Clet a = 5; let b = 10; print(a + b)
Dlet a = 5; let b = 10 print(a + b);
Step-by-Step Solution
Solution:
  1. Step 1: Check semicolon placement

    let a = 5; let b = 10; print(a + b) uses semicolons to separate multiple statements on the same line correctly.
  2. Step 2: Identify syntax errors in other options

    Options A, B, and C miss semicolons between statements on the same line, causing errors. let a = 5; let b = 10 print(a + b); mixes semicolon usage incorrectly.
  3. Final Answer:

    let a = 5; let b = 10; print(a + b) -> Option C
  4. Quick Check:

    Correct semicolon use = D [OK]
Quick Trick: Separate multiple statements on one line with semicolons [OK]
Common Mistakes:
  • Omitting semicolons between statements on the same line
  • Adding unnecessary semicolons after single statements on separate lines
  • Mixing semicolon usage inconsistently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes