Swift Statements

Swift Introduction

📌 Swift Statements

In Swift statements is an instruction that tells the program what to do.

Swift statements are clean, readable, and strictly structured.


 Types of Swift Statements

    Statements are mainly divided into 4 categories:

  1. Declaration Statements

  2. Expression Statements

  3. Control Flow Statements

  4. Jump / Transfer Statements

Let’s understand each one clearly 👇


1️⃣ Declaration Statements

Used to declare variables, constants, functions, and types.

Variable & Constant


Function Declaration



2️⃣ Expression Statements

Any expression that performs an action is a statement.


✔ Function calls
✔ Assignments
✔ Calculations


3️⃣ Control Flow Statements

Used to control the execution flow of the program.


 If Statement


 


 If–Else Statement


 


 Else–If Ladder


 


 Switch Statement

Swift switch is very powerful.


 

✔ No break required
✔ Must cover all cases


4️⃣ Loop Statements

Used to repeat code.


 For-In Loop



 While Loop


 


 Repeat–While Loop

Executes at least once.


 


5️⃣ Jump / Transfer Statements

Used to change execution flow immediately.


 break



 continue



 return



 fallthrough (Switch only)


 


6️⃣ Guard Statement (Very Important 🔥)

Used for early exit and clean code.


✔ Cleaner than if–else
✔ Widely used in iOS apps


🧠 Summary Table

Statement Type Purpose
Declaration Define variables, functions
Expression Perform actions
Control Flow Decision making
Loops Repeat execution
Jump Exit or skip flow
Guard Early validation

You may also like...