# C++ Loops

Loops are used in programming to perform repetitive tasks or execute a block of code multiple times. They are essential for automating processes and handling situations where you need to repeat a specific action under certain conditions. There are two primary types of loops in most programming languages:

1. **For Loops:** These loops are typically used when you know in advance how many times you want to repeat a specific block of code. They consist of three parts: initialization, condition, and increment/decrement. The loop continues to execute as long as the condition is true.
    
    **Syntax:**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695900184249/70d8f62d-1f20-4c5a-98c9-8dcba43186cc.png align="center")
    
    Statement 1 - where we need to do initilization.
    
    Statement 2 - where we need to do condition
    
    Statement 3 - where we need to be increment or decrement.
    
    **Example:**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695899645647/5c35247e-9f81-43f1-a18b-9066906078c1.png align="center")
    
2. **While Loops:** These loops are used when you want to execute a block of code repeatedly until a certain condition becomes false. "while" loops can run indefinitely if the condition never becomes false.
    
    **Syntax:**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695900526291/25415a16-1c69-4de5-ab19-669d24aa0f7a.png align="center")
    
    **Example:**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695900605841/2435cfb3-fe1d-45e9-ad58-c0890e26c363.png align="center")
    
3. **Do- while:** The `do-while` loop is similar to the `while` loop, but the condition is checked after the loop body is executed, so the loop is guaranteed to run at least once.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695899919895/49625e51-c81d-4710-84a3-88041702e024.png align="center")
    

Thanks for reading

Mohammed Muqafamuddin.
