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:
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.
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.
Final Answer:
let a = 5; let b = 10; print(a + b) -> Option C
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
Master "Variables and Constants" in Swift
9 interactive learning modes - each teaches the same concept differently