What does the `break` statement do in C?
A
Skips the current iteration B
Ends the loop or switch immediately C
Repeats the loop D
Pauses the program
Analysis & Theory
`break` immediately exits the current loop or `switch` block.
What does the `continue` statement do in C?
A
Skips the current iteration and goes to the next B
Stops the loop C
Skips all code below it permanently D
Jumps to the end of program
Analysis & Theory
`continue` skips the rest of the current loop iteration and goes to the next cycle.
What is the output?
```c
for (int i = 0; i < 5; i++) {
if (i == 3) break;
printf("%d ", i);
}
```
A
0 1 2 B
0 1 2 3 C
0 1 2 3 4 D
Nothing
Analysis & Theory
`break` exits loop when `i == 3`, so prints `0 1 2`.
What is the output?
```c
for (int i = 0; i < 5; i++) {
if (i == 2) continue;
printf("%d ", i);
}
```
A
0 1 2 3 4 B
0 1 3 4 C
1 2 3 4 D
0 2 3 4
Analysis & Theory
`continue` skips `i == 2`, so 2 is not printed.
Can `break` be used outside loops or `switch` statements?
A
Yes, anywhere B
Only in `if` statements C
No, it gives a compile-time error D
Only in functions
Analysis & Theory
`break` used outside loops or `switch` causes a compile-time error.
What is the output?
```c
int i = 0;
while (i < 5) {
i++;
if (i == 4) break;
printf("%d ", i);
}
```
A
1 2 3 B
1 2 3 4 C
0 1 2 3 D
1 2
Analysis & Theory
`i` becomes 4 and breaks, so prints `1 2 3`.
Where is `break` commonly used in C?
A
Inside functions B
In `switch` and loops C
In header files D
Only in main()
Analysis & Theory
`break` is typically used in `switch`, `for`, `while`, and `do-while` loops.
Which keyword is used to skip the rest of a loop iteration and continue with the next?
A
skip B
jump C
continue D
next
Analysis & Theory
`continue` skips the remaining code in the loop for that iteration.
What is the output?
```c
int i = 0;
do {
i++;
if (i == 2) continue;
printf("%d ", i);
} while (i < 3);
```
A
1 2 3 B
1 3 C
2 3 D
1 2
Analysis & Theory
`i == 2` is skipped due to `continue`, so prints `1 3`.
Can you use both `break` and `continue` in the same loop?
A
No B
Yes C
Only in `for` loop D
Only if nested
Analysis & Theory
You can use both `break` and `continue` in any loop type.