Units 3-4 cover decision-making (conditionals) and repetition (loops) — essential control structures for writing any meaningful program.
Boolean: ==, !=, <, >, <=, >= for primitives. .equals() for String comparison (not ==). Logical: && (and), || (or), ! (not). Short-circuit evaluation: && stops if first is false, || stops if first is true. if (condition) { } else if (condition) { } else { }. De Morgan\'s laws: !(A && B) == !A || !B, !(A || B) == !A && !B. Frequently tested.
while: repeats while condition is true — check before executing. for (init; condition; update) { }: count-controlled loop. for loops are syntactic sugar for while. Nested loops: outer iterates × inner iterates. Off-by-one errors: most common bug. String traversal: for (int i = 0; i < s.length(); i++) { s.charAt(i) }. Common algorithms: find max/min, sum, count, search, reverse.
In Java, == compares references (memory addresses), not content. Two String objects can contain the same text but exist at different memory locations, so == would return false. The .equals() method compares the actual character sequences. Example: String a = new String("hello"); String b = new String("hello"); a == b is false (different objects), a.equals(b) is true (same content). Note: String literals may be cached (interned), so "hello" == "hello" might work, but relying on this is unreliable and bad practice. Always use .equals() for String comparison on the AP exam.
Book a Trial + Diagnostic session. Get a personalized Learning Path with clear milestones, tutor match, and a plan recommendation — all within 24 hours.
Book Trial + Diagnostic →