0
0
Cprogramming~10 mins

Break statement in C - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to exit the loop when i equals 5.

C
for(int i = 0; i < 10; i++) {
    if(i == 5) {
        [1];
    }
    printf("%d\n", i);
}
Drag options to blanks, or click blank then click option'
Acontinue
Breturn
Cexit
Dbreak
Attempts:
3 left
💡 Hint
Common Mistakes
Using continue instead of break, which skips the rest of the loop iteration but does not exit the loop.
Using return or exit which exit the function or program instead of just the loop.
2fill in blank
medium

Complete the code to stop the while loop when count reaches 3.

C
int count = 0;
while(1) {
    if(count == 3) {
        [1];
    }
    printf("Count: %d\n", count);
    count++;
}
Drag options to blanks, or click blank then click option'
Acontinue
Bexit
Cbreak
Dreturn
Attempts:
3 left
💡 Hint
Common Mistakes
Using continue which skips the current iteration but does not exit the loop.
Using exit or return which exit the program or function.
3fill in blank
hard

Fix the error in the code to exit the for loop when num is 7.

C
for(int num = 0; num < 10; num++) {
    if(num == 7) {
        [1];
    }
    printf("%d\n", num);
}
Drag options to blanks, or click blank then click option'
Acontinue
Bbreak
Cexit()
Dreturn
Attempts:
3 left
💡 Hint
Common Mistakes
Using continue which does not exit the loop.
Using exit() or return which exit the program or function.
4fill in blank
hard

Fill both blanks to create a loop that prints numbers until it reaches 4, then stops.

C
for(int i = 0; i < 10; i++) {
    if(i [1] 4) {
        [2];
    }
    printf("%d\n", i);
}
Drag options to blanks, or click blank then click option'
A==
B<
Cbreak
Dcontinue
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of == in the condition.
Using continue instead of break to exit the loop.
5fill in blank
hard

Fill all three blanks to create a loop that stops printing when the character 'q' is found in the array.

C
char letters[] = {'a', 'b', 'c', 'q', 'd'};
for(int [1] = 0; [2] < 5; [3]++) {
    if(letters[i] == 'q') {
        break;
    }
    printf("%c\n", letters[i]);
}
Drag options to blanks, or click blank then click option'
Ai
Dj
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in the loop declaration.
Using a variable not declared or inconsistent.