Recall & Review
beginner
What is the role of semicolons in Swift?
Semicolons in Swift are used to separate multiple statements on the same line, but they are optional at the end of a line if there is only one statement.
Click to reveal answer
beginner
Can you write two Swift statements on the same line without semicolons?
No, when writing two or more statements on the same line, you must separate them with semicolons.
Click to reveal answer
beginner
Is this Swift code valid? <br> <code>let a = 5<br>let b = 10</code>Yes, this code is valid because each statement is on its own line, so semicolons are not needed.
Click to reveal answer
intermediate
How do semicolons affect readability in Swift code?
Using semicolons to put multiple statements on one line can make code harder to read. Swift encourages writing one statement per line without semicolons for clarity.
Click to reveal answer
beginner
Write a Swift line with two statements using semicolons.
Example: <br> <code>let x = 3; let y = 4</code> <br> Semicolons separate the two statements on the same line.Click to reveal answer
In Swift, when are semicolons required?
✗ Incorrect
Semicolons are required only when you put more than one statement on the same line.
Is this Swift code valid? <br>
let a = 1; let b = 2✗ Incorrect
This code is valid because semicolons separate two statements on the same line.
What happens if you omit semicolons when writing multiple statements on the same line in Swift?
✗ Incorrect
Omitting semicolons between multiple statements on the same line causes a compiler error.
Which style does Swift encourage for better readability?
✗ Incorrect
Swift encourages writing one statement per line without semicolons for clarity.
Can you write this Swift code without semicolons? <br>
let x = 10; let y = 20✗ Incorrect
You can remove semicolons by placing each statement on a separate line.
Explain when semicolons are needed in Swift and why they are usually optional.
Think about how Swift treats statements on separate lines versus same line.
You got /3 concepts.
Write an example of Swift code with two statements on the same line using semicolons, and then rewrite it without semicolons on separate lines.
Use let statements for simple variables.
You got /2 concepts.