C++ do…while Loop
🔁 C++ do…while Loop
do…while loop ek exit-controlled loop hai, jisme loop body kam se kam ek baar zaroor execute hoti hai, chahe condition false hi kyon na ho.
🔹 1. Syntax
👉 Note: while ke baad semicolon ; zaroori hota hai.
🔹 2. Basic Example
Output:
🔹 3. Condition False but Loop Runs Once
Output:
👉 Body ek baar execute hui.
🔹 4. Menu-Driven Program Example
🔹 5. User Input Loop
🔹 6. while vs do…while
| while | do…while |
|---|---|
| Entry-controlled | Exit-controlled |
| May run 0 times | Runs at least once |
| Condition first | Code first |
❌ Common Mistakes
✔ Correct:
📌 Summary
-
do…whileloop at least once execute hota hai -
Menu & input validation ke liye best
-
Semicolon after
whileis mandatory
