AP CSA Unit 2 Notes: Mastering Selection and Iteration in Java

0.0(0)
Studied by 0 people
0%Unit 2 Mastery
0%Exam Mastery
Build your Mastery score
multiple choiceMultiple Choice
call kaiCall Kai
Supplemental Materials
Card Sorting

1/49

Last updated 3:08 PM on 3/12/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

50 Terms

1
New cards

Boolean expression

An expression that evaluates to either true or false; used as the condition in if statements and loops.

2
New cards

Selection

Program control that chooses between different paths of execution (e.g., using if/else).

3
New cards

Iteration

Repeating a block of code, typically using loops such as while or for.

4
New cards

Relational operator

An operator that compares ordering (e.g.,

5
New cards

Equality operator

An operator that checks “same vs different” (== or !=) and produces a boolean result.

6
New cards

Logical AND (&&)

Combines two boolean expressions; true only when both parts are true.

7
New cards

Logical OR (||)

Combines two boolean expressions; true when at least one part is true.

8
New cards

Logical NOT (!)

Negates a boolean expression; !true becomes false and !false becomes true.

9
New cards

Operator precedence

Rules Java uses to decide how to group operations in an expression (notably: ! before relational before equality before && before ||).

10
New cards

Parentheses (grouping)

Used to make the intended order of evaluation explicit and reduce mistakes when reading/writing conditions.

11
New cards

Assignment vs comparison (= vs ==)

= assigns a value to a variable, while == compares two values for equality; confusing them is a common condition bug.

12
New cards

Primitive type comparison with ==

For primitives (int, double, char, boolean), == compares the actual stored values.

13
New cards

Object reference comparison (==)

For objects (like String), == checks whether two references point to the same object in memory, not whether contents match.

14
New cards

String content equality (.equals)

Method used to compare Strings by their characters/contents (AP CSA standard for String equality).

15
New cards

NullPointerException (NPE)

A crash that occurs when you call a method (like .equals) on a null reference.

16
New cards

Safe equals pattern ("literal".equals(var))

Calling .equals on a string literal (e.g., "yes".equals(s)) avoids NPE even if the variable is null.

17
New cards

Lexicographic order

Alphabetical-style ordering used for Strings when comparing which comes before/after another.

18
New cards

String.compareTo

A String method that returns a negative number, 0, or a positive number depending on lexicographic ordering relative to another string.

19
New cards

compareTo sign check (

Correct way to interpret compareTo in conditions: test whether the result is less than 0, equal to 0, or greater than 0 (not just -1/0/1).

20
New cards

Range check (inclusive)

A compound condition that checks a value is between bounds, e.g., x >= a && x <= b.

21
New cards

Out-of-range check

A compound condition that checks a value is outside bounds, e.g., x < a || x > b.

22
New cards

Compound boolean expression

A condition built by combining simpler boolean expressions with logical operators like && and ||.

23
New cards

Short-circuit evaluation

Java evaluates && and || left to right and may stop early (false && … stops; true || … stops).

24
New cards

Protective condition ordering

Placing a safety check first (e.g., s != null) so short-circuiting prevents unsafe evaluation (e.g., s.equals(…)).

25
New cards

De Morgan’s laws

Rules for negating compound conditions: !(p && q) ≡ (!p || !q) and !(p || q) ≡ (!p && !q).

26
New cards

if statement

A selection structure that runs its block only when the condition is true; otherwise the block is skipped.

27
New cards

Guard condition

A check used to prevent invalid actions (e.g., checking before dividing by zero or before unsafe operations).

28
New cards

if-else statement

A two-branch structure where exactly one of the two blocks runs (either the if block or the else block).

29
New cards

else-if chain

A multi-branch structure that tests conditions in order; the first true condition runs and the rest are skipped.

30
New cards

Condition ordering (specific to general)

Design principle for else-if chains: order checks so earlier, broader conditions don’t “steal” cases from later ones.

31
New cards

Nested if statement

An if statement placed inside another if/else; useful when one decision depends on a prior decision.

32
New cards

Dangling else

Java rule that an else matches the closest preceding unmatched if, which can cause surprises if braces are omitted.

33
New cards

Braces { } best practice

Using braces around if/else blocks improves readability and prevents else-from-attaching-to-the-wrong-if errors.

34
New cards

while loop

A condition-controlled loop that repeats while a boolean condition is true; best when repetition count isn’t known ahead of time.

35
New cards

Pre-test loop

A loop (like while) that checks its condition before running the body, so it may execute zero times.

36
New cards

Control variable

A variable whose value affects whether a loop continues (must be updated correctly to avoid infinite loops).

37
New cards

Infinite loop

A loop that never ends because its condition never becomes false (often due to missing/incorrect control variable updates).

38
New cards

Off-by-one error

A boundary mistake where a loop runs one too many or one too few times due to incorrect start/stop conditions.

39
New cards

Sentinel value

A special value (e.g., -1) that signals “stop” in a loop.

40
New cards

Sentinel-controlled loop

A loop pattern that continues until a sentinel value is encountered; requires updating the sentinel-related variable inside the loop.

41
New cards

Loop invariant

An idea for tracing/debugging: a statement that remains true each time the loop condition is checked, helping you stay oriented.

42
New cards

for loop

A count-controlled loop that bundles initialization, condition, and update; best when the number of iterations is known or expressible.

43
New cards

for loop header (init; condition; update)

The three-part structure of a for loop: run initialization once, test condition before each iteration, then apply update after the body.

44
New cards

for-to-while equivalence

A for loop can be rewritten as a while loop by moving initialization before the loop and the update to the end of the loop body.

45
New cards

Loop variable scope

A variable declared in a for header (e.g., int i = 0) exists only within the loop (header and body), not after it ends.

46
New cards

Nested loop

A loop inside another loop, used to repeat a repeated process (common in tracing and pattern problems).

47
New cards

Outer loop vs inner loop execution

In nested loops, the inner loop runs start-to-finish for each single iteration of the outer loop; total executions often multiply.

48
New cards

Pattern printing with nested loops

Using an outer loop for rows and an inner loop for columns to build repeated text patterns (e.g., rectangles of *).

49
New cards

System.out.print vs System.out.println

print outputs without a newline; println outputs and then ends the line—this changes traced output formatting.

50
New cards

break statement

A Java statement that immediately exits the nearest loop; AP CSA emphasizes understanding loop conditions rather than relying heavily on break.

Explore top notes

note
Capacity and Surrogacy
Updated 1390d ago
0.0(0)
note
Guía Matemáticas 2-3
Updated 638d ago
0.0(0)
note
chapter 6 vocab
Updated 452d ago
0.0(0)
note
Musical Forms And Devices
Updated 613d ago
0.0(0)
note
🧬 AP Biology Unit 6
Updated 317d ago
0.0(0)
note
Elementary Logic
Updated 795d ago
0.0(0)
note
Capacity and Surrogacy
Updated 1390d ago
0.0(0)
note
Guía Matemáticas 2-3
Updated 638d ago
0.0(0)
note
chapter 6 vocab
Updated 452d ago
0.0(0)
note
Musical Forms And Devices
Updated 613d ago
0.0(0)
note
🧬 AP Biology Unit 6
Updated 317d ago
0.0(0)
note
Elementary Logic
Updated 795d ago
0.0(0)

Explore top flashcards

flashcards
AP Statistics Ultimate Review
91
Updated 310d ago
0.0(0)
flashcards
Vocab 10-12
60
Updated 1095d ago
0.0(0)
flashcards
Lecture 5: Pain
54
Updated 535d ago
0.0(0)
flashcards
El tiempo (the weather)
33
Updated 837d ago
0.0(0)
flashcards
La Familia Level 1
25
Updated 1156d ago
0.0(0)
flashcards
chapter 2 science vocab
20
Updated 382d ago
0.0(0)
flashcards
AP Statistics Ultimate Review
91
Updated 310d ago
0.0(0)
flashcards
Vocab 10-12
60
Updated 1095d ago
0.0(0)
flashcards
Lecture 5: Pain
54
Updated 535d ago
0.0(0)
flashcards
El tiempo (the weather)
33
Updated 837d ago
0.0(0)
flashcards
La Familia Level 1
25
Updated 1156d ago
0.0(0)
flashcards
chapter 2 science vocab
20
Updated 382d ago
0.0(0)