C Control Flow Formula Sheet and Revision Notes: Conditionals, Loops and Jumps
Revise C control flow through compact rules, boundary-safe loop formulas and exact traces for short-circuiting, switch fall-through, nested loops, break and continue.
KnowledgeGate Team
Exam prep & CS education

Control-flow questions combine truth values, short-circuiting, fall-through, loop boundaries and jump targets in a few lines. A reliable trace evaluates each branch before moving on: short-circuiting can leave y=4, switch fall-through can leave total=11, nested bounds can produce 15 executions, and a break/continue loop can finish at i=5, sum=8. For the basic sequence, selection, iteration and jump-statement overview, read Control Flow in C Programming: If-Else, Loops, Switch and Jump Statements with Worked Examples. Boundary-safe counts, nested-loop arithmetic and numeric traces extend that foundation. Practice modules are available in Learn.
1. C control-flow truth rules and short-circuit checks
Rule | Value to remember |
|---|---|
False | Integer value |
True | Any non-zero scalar value |
Relational and logical result | Integer |
Logical negation |
|
When to use: Normalise the value reaching a condition before tracing its branch.
For &&, the right side runs only if the left is true; for ||, only if the left is false. In int x=0, y=4; int r=(x!=0) && (++y>4);, x!=0 gives 0, so ++y is skipped and the result is r=0, y=4.
When to use: Check whether evaluation actually reaches a side effect on the right.
Do not confuse comparison with assignment. In int x=0; if (x=5) ..., assignment stores 5, whose non-zero value runs the branch. Parenthesise complex conditions, and use the operator-precedence rules for precedence details.
2. if, else-if, nested if and the conditional operator
An if runs its body when its condition is true. An else-if ladder stops at the first true condition. An else binds to the nearest unmatched if, and braces make that binding explicit.
When to use: Choose one path from ordered or nested tests.
Trace int x=7, y=4, score=0; if (x>5) { if (y%2==0) score+=10; else score+=3; } else score-=2;. Both tests are true, so score becomes 10. With x=4, the outer else would give -2. With x=7, y=5, the inner else would give 3.
The conditional operator, condition ? value_if_true : value_if_false, yields one of two values. It does not replace every statement-level branch. Thus int max=(7>4)?7:4; sets max=7. See the conditional-branch examples for a deeper walkthrough.
3. switch fall-through and jump-statement targets
A switch controlling expression has integer type, and each case is an integer constant expression. Duplicate values are invalid; default is optional. Execution continues from the matching label until break, return or the switch ends.
When to use: Match one integer-like value against discrete constant choices.
Trace char op='+'; int total=10; switch(op) { case '+': total+=2; case '-': total-=1; break; default: total=0; }. Entry at case '+' changes 10 -> 12; fall-through to case '-' changes 12 -> 11. Then break exits, so total=11. A break after total+=2 would leave total=12.
break exits the nearest loop or switch. continue advances the nearest loop to its next iteration step. return exits the function. goto label transfers within that function to the named label. A continue inside a switch nested in a loop therefore continues the loop, not the switch. For focused switch and jump destinations, read Switch and Jump Statements in C: Concepts, Traces and Exam Traps. Its destination semantics pair with loop-boundary formulas and nested counts in this revision set.
4. for, while and do-while formulas with boundary checks
Construct | Order | When to use |
|---|---|---|
|
| Clear initialisation and update |
| Test before the body | Zero runs must be possible |
| Body before test | At least one run is required |
for(i=a; i<=b; i+=s) has floor((b-a)/s)+1 iterations when s>0 and a<=b.
When to use: Fixed positive step, unchanged inclusive upper bound.
At a=3, b=13, s=4, floor(10/4)+1=2+1=3, matching 3, 7, 11; 15 fails. The decreasing mirror is floor((a-b)/s)+1 for for(i=a; i>=b; i-=s), s>0, a>=b.
When to use: Fixed positive decrement, unchanged inclusive lower bound.
For for(i=a; i<b; i+=s), s>0, the count is max(0, ceil((b-a)/s)).
When to use: Fixed positive step, unchanged exclusive upper bound.
At a=2, b=11, s=3, ceil(9/3)=3, matching 2, 5, 8; 11 fails. For positive integer x, while(x>0) { x/=2; } runs floor(log2(x))+1 times.
When to use: Positive integer halving by truncating division until zero.
At x=20, entries 20, 10, 5, 2, 1 give 5 iterations before zero. The Loops and Iteration in C: for, while, do-while, Worked Traces and Exam Patterns walkthrough develops state-change traces; use these formulas when the loop start, stop or step changes.
5. Nested-loop counts: product, sum and triangular growth
Independent fixed iteration counts multiply. A dependent inner bound must be summed across outer values.
When to use: Multiply only when every outer pass has the same inner count. Otherwise, write the inner counts as a series first.
For for(i=0; i<3; i++), outer values 0, 1, 2 give 3 passes. Inside, for(j=2; j<=8; j+=3) visits 2, 5, 8, or 3 times per pass. The body executes 3*3=9 times.
Now trace count=0; for(i=1; i<=4; i++) for(j=1; j<=i; j++) count++;. The inner counts are 1, 2, 3, 4, so the total is 1+2+3+4=10. This agrees with n(n+1)/2=4*5/2=10. That formula belongs to this exact 1 through i pattern. Changed starts or steps require a fresh sum.
Distinguish body entries from updates or prints. A continue, break, condition or skipped print can make those totals differ from the loop-header count.
6. break and continue: one complete control-flow trace

Use the program exactly as written:
int i=0, sum=0;
while(i<5) {
++i;
if(i==2) continue;
if(i==5) break;
sum+=i;
}Pass |
| Branch | Sum before | Addition | Sum after |
|---|---|---|---|---|---|
1 | 1 | No jump | 0 | 1 | 1 |
2 | 2 |
| 1 | None | 1 |
3 | 3 | No jump | 1 | 3 | 4 |
4 | 4 | No jump | 4 | 4 | 8 |
5 | 5 |
| 8 | None | 8 |
On pass 2, continue skips both the later if and sum+=i, then returns to the while test. On pass 5, break exits before the addition. The final state is i=5, sum=8. If the only increment were below a reachable continue, that increment could be skipped and the loop might stop progressing.

7. How GATE-style questions use control flow, and the traps to remove
IIT Guwahati's GATE 2026 CS syllabus lists Programming in C under Programming and Data Structures. That supports revising C, but the document does not assign control flow a separate weightage.
Common practice questions ask you to predict nested-selection output, count loop executions, detect skipped short-circuit side effects, trace fall-through, identify a jump's target, or decide whether code terminates. These are practice forms, not a guaranteed paper pattern.
Trap | What actually happens | Correction |
|---|---|---|
| Assigns | Use |
Semicolon after | Creates an empty loop body | Remove it unless intentional |
Missing switch | Permits fall-through | Trace until an exit |
| Omitted condition stays true indefinitely | Find its reachable exit |
| Has no portable defined result in C | Reject a fixed-output shortcut |
Only increment below | May prevent progress | Update before the jump or restructure |
8. C control flow in the short version, then one revision step
Zero is false; non-zero is true.
&&and||may skip the right operand.An
elsebinds to the nearest unmatchedif.Switch cases fall through without an exit.
Pre-test loops may run zero times;
do-whileruns at least once.break,continueandreturnhave different targets.
Take ten minutes and recover r=0, y=4; total=11; 3, 7, 11 and 3 iterations; 3+5+7=15; then i=5, sum=8, without code. For broader C practice, use the C Language course.
Keep learning
C Fundamentals Formula Sheet for GATE CS: Rules, Traces and Revision Notes
Revise the C rules that most often change an answer. Use compact tables, worked traces, address formulas, memory notes, and a practical error checklist.
Storage Classes, Structures and Enums in C: Formula Sheet with Worked Revision
Revise C declarations through three separate axes, then test them with a two-call trace, a byte-layout calculation and an enum sequence.
DMA, Macros, Scoping and File Handling in C: Formula Sheet with Worked Revision Notes
Build a compact C revision sheet for dynamic memory, macros, scope, linkage, storage duration and file streams. Four worked checks connect each rule to an exact result.
C Programming by Yash Sir Formula Sheet: Rules, Traces and Revision Notes
Revise C through compact rules, use cues and checked traces. The sheet covers expressions, loops, arrays, functions, storage and dynamic memory.





