Bird
0
0

You want to write two Swift statements on the same line: let name = "Alice" and print(name). Which is the correct way to write this?

hard📝 Application Q15 of 15
Swift - Variables and Constants
You want to write two Swift statements on the same line: let name = "Alice" and print(name). Which is the correct way to write this?
Alet name = "Alice"; print(name)
Blet name = 'Alice'; print(name);
Clet name = "Alice" print(name);
Dlet name = "Alice" print(name)
Step-by-Step Solution
Solution:
  1. Step 1: Understand semicolon use on same line

    When writing multiple statements on the same line, separate them with a semicolon.
  2. Step 2: Check each option for correctness

    let name = "Alice"; print(name) correctly separates the two statements with a semicolon and omits unnecessary semicolon at the end.
  3. Final Answer:

    let name = "Alice"; print(name) -> Option A
  4. Quick Check:

    Separate statements on one line with semicolon [OK]
Quick Trick: Use one semicolon between statements on the same line [OK]
Common Mistakes:
  • Omitting semicolon between statements
  • Adding extra semicolon after last statement unnecessarily
  • Writing statements without separation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes