๐Ÿ‡ฎ๐Ÿ‡ณ India's Free Coding Tutorial โ€” Learn C, PHP, MySQL, Python, Java About ยท Contact
Advertisement

do-while Loop

C Language Control Flow ๐Ÿ“… Mar 2026 โฑ 5 min read ๐Ÿ†“ Free

do-while Loop

Executes the body at least once, then checks the condition.

c
#include <stdio.h>
int main() {
    int choice;
    do {
        printf("
=== MENU ===
");
        printf("1. Add
2. Subtract
3. Exit
");
        printf("Enter choice: ");
        scanf("%d", &choice);
        
        if (choice == 1) printf("Add selected
");
        else if (choice == 2) printf("Subtract selected
");
    } while (choice != 3);
    
    printf("Goodbye!
");
    return 0;
}
Key Difference while checks condition before loop. do-while checks after loop. Menu programs always use do-while because the menu must show at least once.
Advertisement
โ† Back to C Language Index