The two major types of loops in programming are:
1. **For Loop**:
- A `for loop` is used when you know beforehand how many times you want to repeat a block of code.
- It's often used for iterating over a range of values or through a collection (like a list or array).
- Example (in Python):
```python
for i in range(5): # Loop will run 5 times
print(i)
```
2. **While Loop**:
- A `while loop` is used when you want to repeat a block of code as long as a certain condition is true.
- It's commonly used when you donβt know in advance how many iterations are needed.
- Example (in Python):
```python
i = 0
while i < 5: # Loop will run as long as i is less than 5
print(i)
i += 1
```
In short, a **for loop** is typically used for a known number of iterations, while a **while loop** is used when the number of iterations depends on a condition.