# Introduction to Looping Constructs

### **Introduction to Looping Constructs**

Looping constructs are VHDL instructions that allow a program to repeat the same block of code, a process known as **iteration** (similar to C).

Loops in VHDL are divided into two main categories based on how they function and what they create.

---

#### **1. Sequential Loops (Inside a `process`)**

These loops are similar to those in traditional programming languages. They describe an **algorithm** or a sequence of operations that execute step-by-step.

- They can **only** be used inside a `process`, `function`, or `procedure`.
- They are synthesized into hardware that performs an operation over multiple clock cycles or as a large block of combinational logic.

There are two main types of sequential loops:

- **`for` loop** -> Repeats for a specific number of times. Use this when you know the exact number of iterations.

- **`while` loop** -> Repeats as long as a certain condition is `true`. Use this when the number of iterations is unknown.

---

#### **2. Concurrent Loops (Outside a `process`)**

This type of loop is unique to hardware description languages. It doesn't describe an algorithm but instead describes the **replication of hardware structures**. It acts like copy and pasting ICs on a breadboard. 

![image](https://hackmd.io/_uploads/SJRoqOThgx.png)

(well, that's the gist of it)

- It creates multiple instances of concurrent statements (like component instantiations).
- It is **only** used **outside** of a `process`, in the main architectural body.

- The main type is the **`for-generate` loop**.