đ do-while Loop in C
đ Short Explanation:
The do-while loop executes the code block at least once, then repeats it while the condition remains true. The condition is checked after the block runs.
✅ Syntax
do {
// code block
} while (condition);
đ Example: Print 1 to 5
#include <stdio.h>
int main() {
int i = 1;
do {
printf("%d\\n", i);
i++;
} while (i <= 5);
return 0;
}
đ§ Output: 1 2 3 4 5
đĄ Common Use Cases
- Menus where at least one prompt is shown
- Input validation loops
- Repeating code that must run once before checking condition
⚠️ Tips & Best Practices
- Useful when you want the loop to run at least once
- Remember the semicolon
;afterwhile(condition) - Watch out for infinite loops by ensuring condition changes inside loop
đ Summary
The do-while loop ensures your code runs at least once, then continues repeating as long as the condition is true. Great for menus and input prompts.
āĻোāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāĻ:
āĻāĻāĻি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āĻ āĻāϰুāύ