0
0
Cprogramming~20 mins

Loop execution flow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Loop Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of nested for loops with break

What is the output of the following C code?

C
#include <stdio.h>

int main() {
    for (int i = 1; i <= 3; i++) {
        for (int j = 1; j <= 3; j++) {
            if (j == 2) {
                break;
            }
            printf("%d%d ", i, j);
        }
    }
    return 0;
}
A11 12 21 22 31 32
B11 21 31
C11 12 13 21 22 23 31 32 33
D12 22 32
Attempts:
2 left
💡 Hint

Remember that break exits the innermost loop immediately.

Predict Output
intermediate
2:00remaining
Output of while loop with continue

What is the output of this C program?

C
#include <stdio.h>

int main() {
    int i = 0;
    while (i < 5) {
        i++;
        if (i == 3) {
            continue;
        }
        printf("%d ", i);
    }
    return 0;
}
A2 3 4 5
B1 2 3 4 5
C1 2 4
D1 2 4 5
Attempts:
2 left
💡 Hint

Think about what continue does inside a loop.

Predict Output
advanced
2:00remaining
Output of for loop with multiple increments

What is the output of this C code?

C
#include <stdio.h>

int main() {
    for (int i = 0; i < 5; i++) {
        printf("%d ", i);
        i++;
    }
    return 0;
}
A0 2 4
B0 1 2 3 4
C0 1 3
D1 3 5
Attempts:
2 left
💡 Hint

Notice the extra i++ inside the loop body.

Predict Output
advanced
2:00remaining
Output of do-while loop with break

What is the output of this C program?

C
#include <stdio.h>

int main() {
    int i = 0;
    do {
        if (i == 2) {
            break;
        }
        printf("%d ", i);
        i++;
    } while (i < 5);
    return 0;
}
A0 1 2
B0 1 2 3 4
C0 1
D1 2
Attempts:
2 left
💡 Hint

Remember that break exits the loop immediately.

🧠 Conceptual
expert
2:00remaining
Number of iterations in nested loops with variable increments

Consider this C code snippet:

int count = 0;
for (int i = 1; i <= 4; i += 2) {
    for (int j = 0; j < i; j++) {
        count++;
    }
}

What is the final value of count after the loops finish?

A4
B10
C8
D12
Attempts:
2 left
💡 Hint

Calculate how many times the inner loop runs for each i value.