4.1 Decision Making: if, if-else, nested if, switch
if executes a block only when a condition is true. if-else provides an alternate branch when it is false. Nested if chains (else if) test a series of conditions in order. switch compares one variable against multiple constant case values — a cleaner alternative to long else-if chains, but it only supports equality checks on integral/char/enum types, and each case usually needs a break to prevent 'fall-through' into the next case.
if (marks >= 90) printf("Grade A");
else if (marks >= 75) printf("Grade B");
else printf("Grade C");
switch (day) {
case 1: printf("Monday"); break;
case 2: printf("Tuesday"); break;
default: printf("Invalid");
}
4.2 Loops: for, while, do-while
Loops repeat a block until a condition fails. for is ideal when the number of iterations is known (it bundles init, condition, update in one line). while checks the condition before each iteration — the body may run zero times. do-while checks the condition after the body — guaranteeing at least one execution, useful for menu-driven programs.
for (int i = 0; i < 5; i++) { printf("%d ", i); }
int i = 0;
while (i < 5) { printf("%d ", i); i++; }
int i = 0;
do { printf("%d ", i); i++; } while (i < 5);
4.3 break, continue, and goto
break immediately exits the nearest enclosing loop or switch. continue skips the rest of the current iteration and jumps to the loop's update/condition step. goto performs an unconditional jump to a labeled statement — powerful but discouraged in modern code because it can make control flow hard to follow; it survives mainly for breaking out of deeply nested loops or centralized error-cleanup.
break: Abruptly breaks out of the innermostfor,while,do-whileloop, orswitchblock. Execution immediately resumes at the statement right after the loop's closing brace.continue: Bypasses all subsequent statements in the current iteration of a loop. In aforloop, it jumps straight to the increment/update step (i++); inwhileanddo-whileloops, it jumps straight to the conditional re-evaluation.goto: Jumps unconditionally to a user-defined label (goto error_handler;). While heavily discouraged in structured programming due to creating unmaintainable "spaghetti code", it remains standard practice in C systems code (such as the Linux kernel) for unified error cleanup and escaping deeply nested multi-level matrix loops.