A Boolean expression evaluates to true or false, usually built with relational operators (<, >, <=, >=, ==, !=). Selection statements use these to choose which code runs: if executes a block when a condition is true, if/else chooses between two blocks, and nested if / else-if chains handle multiple cases in order. Remember to use == (not =) to test equality, and .equals() to compare objects like Strings.
Booleanif / elseRelational Ops
Key Concept 2
Logical operators combine and negate conditions
Compound conditions use the logical operators&& (AND), || (OR), and ! (NOT). Java uses short-circuit evaluation: in a && b it skips b when a is false, and in a || b it skips b when a is true. You can rewrite negated compound conditions with De Morgan’s laws — !(a && b) equals !a || !b, and !(a || b) equals !a && !b — and confirm equivalence with truth tables.
&& || !Short-CircuitDe Morgan
Key Concept 3
Loops repeat code, and nested loops multiply it
Iteration repeats a block of code. A while loop repeats as long as its condition is true (good for open-ended repetition), and a for loop bundles initialization, condition, and update for counting. Loops power String traversals and standard algorithms. A nested loop runs its inner loop fully for each outer iteration — two n-loops give n² executions. Watch for infinite loops and off-by-one errors, and use informal run-time analysis to count executions.
while / forNested LoopsRun-Time
Boolean expression
An expression evaluating to true or false.
Boolean
Relational operator
< > <= >= == != comparing two values.
Boolean
== vs. =
Equality test vs. assignment.
Boolean
if statement
Runs a block when a condition is true.
Selection
if/else statement
Chooses between two blocks based on a condition.
Selection
Nested if / else-if
Conditions checked in order; first true branch runs.