Swift Syntax
✨ Swift Syntax (Basics Explained Clearly)
1. Swift Program Structure
A basic Swift program looks like this:
✔ No main() function
✔ No semicolons required
✔ Code runs top-to-bottom
2. Comments in Swift
Comments are ignored by the compiler.
Single-line comment
Multi-line comment
3. Variables & Constants
Variable (var) – value can change
Constant (let) – value cannot change
✅ Swift prefers constants (let) for safety
4. Data Types
Swift can automatically detect types, but you can also define them.
5. Type Inference
Swift automatically understands data types:
6. String Interpolation
Insert variables inside strings easily:
Output:
7. Operators
Arithmetic Operators
Comparison Operators
8. If–Else Condition
✔ Curly braces {} are mandatory
9. Switch Statement
More powerful than other languages:
✔ No break needed
✔ Must be exhaustive
10. Loops
For Loop
While Loop
11. Functions
12. Semicolons?
Optional (not recommended):
Swift Syntax Highlights
✔ Clean & readable
✔ Strong type safety
✔ No boilerplate
✔ Beginner-friendly
✔ Modern features
