0
0
Cprogramming~20 mins

Do–while loop in C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Do–while Loop Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple do–while loop
What is the output of this C code?
C
int main() {
    int i = 1;
    do {
        printf("%d ", i);
        i++;
    } while (i <= 3);
    return 0;
}
A1 2 3
B1 2
CNo output
D2 3
Attempts:
2 left
💡 Hint
Remember, do–while executes the loop body before checking the condition.
Predict Output
intermediate
2:00remaining
Do–while loop with initial false condition
What will this program print?
C
int main() {
    int i = 5;
    do {
        printf("%d ", i);
        i++;
    } while (i < 5);
    return 0;
}
A5 6
BNo output
CRuntime error
D5
Attempts:
2 left
💡 Hint
The loop body runs once before the condition is checked.
Predict Output
advanced
2:30remaining
Nested do–while loops output
What is the output of this nested do–while loop code?
C
int main() {
    int i = 1, j;
    do {
        j = 1;
        do {
            printf("%d%d ", i, j);
            j++;
        } while (j <= 2);
        i++;
    } while (i <= 2);
    return 0;
}
A11 21 12 22
B11 12 21 22
C12 11 22 21
D11 12 22 21
Attempts:
2 left
💡 Hint
The inner loop runs fully for each iteration of the outer loop.
Predict Output
advanced
2:00remaining
Do–while loop with break statement
What will this program print?
C
int main() {
    int i = 1;
    do {
        if (i == 3) break;
        printf("%d ", i);
        i++;
    } while (i <= 5);
    return 0;
}
A1 2 3
B1 2 3 4 5
C1 2
DNo output
Attempts:
2 left
💡 Hint
The break stops the loop when i equals 3 before printing.
Predict Output
expert
2:30remaining
Value of variable after do–while loop with complex condition
What is the value of variable x after this code runs?
C
int main() {
    int x = 0, y = 5;
    do {
        x += y;
        y--;
    } while (y > 0);
    printf("%d", x);
    return 0;
}
A15
B10
C5
D0
Attempts:
2 left
💡 Hint
Sum y from 5 down to 1 added to x.