Govt. Exams
Entrance Exams
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
if(i + j == 1) continue;
printf("Done");
continue only affects the inner loop, not the outer. The loops complete normally and 'Done' is printed once after both loops finish.
if(1) if(0) printf("A"); else printf("B");
The else binds to the nearest if (inner if). Outer if(1) is true, inner if(0) is false, so else executes printing 'B'.
Case labels must be constant integral expressions (int, char, etc.). Floating-point constants are not allowed as case labels.
int x = 0;
for(int i = 1; i
continue skips even values. x accumulates: 1(i=1) + 3(i=3) + 5(i=5) = 9. Values i=2,4 are skipped.
for(int i = 0; i < 3; i++) {
if(i == 1) goto skip;
printf("%d ", i);
}
skip: printf("End");
When i=1, goto skip jumps to the skip label, skipping the printf. i continues to 2 in the loop. Output: 0 2 End
int x = 5;
switch(x) {
case 5: printf("Five");
case 6: printf("Six");
default: printf("Default");
}
Without a break statement after case 5, control falls through to case 6 and default. This is called fall-through behavior in switch statements.
'goto' transfers control to the label specified, which can be anywhere in the program. It can jump out of nested structures to the labeled location.
for(int i = 1; i
The break statement only exits the inner loop. When i=2 and j=1, inner loop breaks. i=3 executes normally. Output: 11 31 32
int i = 0;
while(i < 3) {
printf("%d ", i++);
if(i == 2) continue;
}
The loop prints 0, then i becomes 1. When i becomes 2, continue skips the rest but the loop continues. i becomes 3 and loop exits. Output: 0 1 2
A switch statement is ideal for menu-driven programs where you match user input against specific cases. It's more efficient and readable than multiple if-else statements for this purpose.