What it covers: Boolean expressions, if/else and nested selection, logical operators and De Morgan’s laws, while and for loops, nested iteration, String algorithms, and informal run-time analysis.
Exam weight: About 25–35% of the multiple-choice section — one of the largest units.
The big question: How do programs make decisions and repeat actions?
Computational thinking practices: Design Code, Develop Code, Analyze Code, Document Code, and Use Computers Responsibly.
Key topics at a glance
Relational Operators
< > <= >= == != compare values and produce a boolean. Use == to test equality, = to assign.
if / if-else
if (cond) { } runs the body when true; if (cond) { } else { } runs exactly one branch.
Nested & else-if
Chain conditions with else if; the first true branch runs and the rest are skipped.
Logical Operators
&& (AND: both true), || (OR: at least one true), ! (NOT: flips). Short-circuit: evaluation stops once the result is known.
De Morgan’s Laws
!(a && b) = !a || !b and !(a || b) = !a && !b. Use to simplify negated conditions.
while Loop
while (cond) { } repeats while the condition is true. Must make progress or it becomes an infinite loop.
for Loop
for (init; cond; update) { }. Example: for (int i = 0; i < n; i++) runs n times (i = 0..n−1).
Nested Iteration
A loop inside a loop; inner runs fully for each outer pass. Two n-loops → n² inner executions.
The key terms and rules you must know
Boolean expression — evaluates to true or false.
Relational operators — < > <= >= == !=.
= vs. == — assignment vs. equality test.
if / if-else — one-way and two-way selection.
Logical operators — && (and), || (or), ! (not).
Short-circuit evaluation — stops once the result is known.
De Morgan’s laws — !(a&&b)=!a||!b; !(a||b)=!a&&!b.
while loop — repeats while a condition is true.
for loop — init; condition; update.
Infinite loop — a condition that never becomes false.
Off-by-one error — looping one too many/few times.
Nested iteration — a loop inside a loop (n²).
Key themes to remember
Selection makes decisions. Boolean expressions choose which code runs.
Iteration repeats work. while for open-ended, for for counting.
&& and || short-circuit. The right side may never run.
Trace loops carefully. Track the loop variable and condition each pass.
Nested loops multiply. Inner runs fully for every outer iteration.
Common exam traps
Use == for equality, = for assignment. Mixing them is a classic bug.
Compare Strings with .equals(), not == (which compares references).
< vs. <= changes the count by one — watch off-by-one errors.
Update the loop variable or a while loop runs forever.
else binds to the nearest if — use braces to control grouping.
Short-circuit matters: in a && b, b is skipped when a is false.