AP Computer Science a Quiz: Comparing Boolean Expressions
15 questions · exam conditions
0:00
Comparing Boolean ExpressionsQuestion 1 of 15

A simulation uses isSimulationRunning and isErrorDetected:

while (isSimulationRunning)
  if (isErrorDetected)
    isSimulationRunning = false
  ticks = ticks + 1

How does the program flow change when isSimulationRunning becomes false inside the loop?

The loop condition fails next check and stops
The loop stops before ticks increments
The loop continues until ticks reaches 0
The loop restarts immediately without checking
← Back to quizzes

AP Computer Science a Quiz

AP Computer Science a Quiz: Comparing Boolean Expressions

Practice Comparing Boolean Expressions in AP Computer Science a with focused quiz questions that help you check what you know, review explanations, and build confidence with test-style prompts.

What this quiz covers

This quiz focuses on Comparing Boolean Expressions, giving you a quick way to practice the rules, question types, and explanations that matter most for AP Computer Science a.

How to use this quiz

Try each quiz question before looking at the correct answer. Use the explanations to review missed ideas, then come back to similar questions until the pattern feels familiar.

All questions

Question 1

A simulation uses isSimulationRunning and isErrorDetected:

while (isSimulationRunning)
  if (isErrorDetected)
    isSimulationRunning = false
  ticks = ticks + 1

How does the program flow change when isSimulationRunning becomes false inside the loop?

  1. The loop condition fails next check and stops (correct answer)
  2. The loop stops before ticks increments
  3. The loop continues until ticks reaches 0
  4. The loop restarts immediately without checking

Explanation: This question tests understanding of comparing Boolean expressions in AP Computer Science A, focusing on logical evaluation and selection/iteration concepts. Boolean expressions are logical statements that evaluate to true or false, guiding program flow through conditional constructs like if statements and loops. In the provided scenario, when isSimulationRunning becomes false inside the loop, it affects the next iteration's condition check. Choice A is correct because after isSimulationRunning is set to false, the loop completes its current iteration (including incrementing ticks), then checks the condition again at the start of the next iteration, finds it false, and stops. Choice B is incorrect because it suggests the loop stops immediately without completing the current iteration, misunderstanding loop execution flow. To help students: Emphasize that changes to loop variables inside the loop body don't affect the current iteration but impact the next condition check. Watch for: Confusion about when loop conditions are checked and the order of operations within a loop iteration.

Question 2

In access control, hasValidCredentials and isAccountActive are used:

if (hasValidCredentials)
  if (isAccountActive)
    result = "LOGIN"
  else
    result = "INACTIVE"
else
  result = "FAIL"

What does the Boolean expression hasValidCredentials && !isAccountActive signify in the provided code?

  1. User can log in successfully
  2. Credentials are valid but account is inactive (correct answer)
  3. Credentials are invalid and account is inactive
  4. Account is active regardless of credentials

Explanation: This question tests understanding of comparing Boolean expressions in AP Computer Science A, focusing on logical evaluation and selection/iteration concepts. Boolean expressions are logical statements that evaluate to true or false, guiding program flow through conditional constructs like if statements and loops. In the provided scenario, the expression hasValidCredentials && !isAccountActive represents a specific state where credentials are valid but the account is inactive. Choice B is correct because this expression evaluates to true only when hasValidCredentials is true AND isAccountActive is false (making !isAccountActive true), which signifies valid credentials with an inactive account status. Choice A is incorrect because it describes the opposite scenario where both conditions are positive, missing the NOT operator's effect. To help students: Emphasize reading Boolean expressions as English statements - "has valid credentials AND account is NOT active". Watch for: Students overlooking the NOT operator or misinterpreting its effect on the overall meaning.

Question 3

A form validator uses isEmailValid and isPasswordSecure:

if (!isEmailValid || !isPasswordSecure)
  showError = true
else
  showError = false

for each attempt
  if (showError)
    attempts = attempts + 1

What will be the output of the following code if isEmailValid is true and isPasswordSecure is true?

  1. showError becomes true
  2. showError becomes false (correct answer)
  3. showError becomes true, then false
  4. showError remains unspecified by default

Explanation: This question tests understanding of comparing Boolean expressions in AP Computer Science A, focusing on logical evaluation and selection/iteration concepts. Boolean expressions are logical statements that evaluate to true or false, guiding program flow through conditional constructs like if statements and loops. In the provided scenario, the condition (!isEmailValid || !isPasswordSecure) checks if either field is invalid to determine whether to show an error. Choice B (showError becomes false) is correct because when both isEmailValid and isPasswordSecure are true, the condition becomes !true || !true = false || false = false, so the else branch executes setting showError to false. Choice A is incorrect because it assumes the if condition is true, not recognizing that both NOT operations create false values. To help students: Practice evaluating expressions with multiple NOT operators and trace through both branches of if-else statements. Watch for: Students forgetting to apply NOT operators or misunderstanding how OR combines false values.

Question 4

A simulation loop uses isSimulationRunning and isErrorDetected:

while (isSimulationRunning && !isErrorDetected)
  steps = steps + 1
  if (steps > maxSteps)
    isSimulationRunning = false

How does the program flow change when isErrorDetected becomes true?

  1. The while loop stops immediately (correct answer)
  2. The while loop runs one extra time
  3. Only maxSteps is checked, loop continues
  4. steps resets to 0 and loop restarts

Explanation: This question tests understanding of comparing Boolean expressions in AP Computer Science A, focusing on logical evaluation and selection/iteration concepts. Boolean expressions are logical statements that evaluate to true or false, guiding program flow through conditional constructs like if statements and loops. In the provided scenario, the while loop condition (isSimulationRunning && !isErrorDetected) controls loop execution, requiring both conditions to be met for continuation. Choice A is correct because when isErrorDetected becomes true, the condition becomes isSimulationRunning && !true = isSimulationRunning && false = false, causing the loop to terminate immediately. Choice B is incorrect because it suggests the loop runs again after the condition becomes false, misunderstanding how while loops check their condition before each iteration. To help students: Emphasize that while loops check their condition at the start of each iteration and stop immediately when the condition becomes false. Watch for: Confusion about when loop conditions are evaluated and the immediate effect of condition changes.

Question 5

An algorithm selector compares isDataSorted and isResourceAvailable:

if (!isDataSorted && isResourceAvailable)
  plan = "SORT_THEN_FAST"
else
  plan = "DIRECT"

for each item
  if (plan == "DIRECT")
    ops = ops + 1

Which Boolean expression evaluates to true given isDataSorted is true and isResourceAvailable is true?

  1. !isDataSorted && isResourceAvailable
  2. isDataSorted && isResourceAvailable (correct answer)
  3. !isDataSorted || isResourceAvailable
  4. !(isDataSorted && isResourceAvailable)

Explanation: This question tests understanding of comparing Boolean expressions in AP Computer Science A, focusing on logical evaluation and selection/iteration concepts. Boolean expressions are logical statements that evaluate to true or false, guiding program flow through conditional constructs like if statements and loops. In the provided scenario, we need to identify which expression evaluates to true when both isDataSorted and isResourceAvailable are true. Choice B (isDataSorted && isResourceAvailable) is correct because it evaluates to true && true = true, as the AND operator requires both operands to be true. Choice A is incorrect because it would evaluate to !true && true = false && true = false, with the NOT operator making the first part false. To help students: Practice evaluating expressions systematically, applying operators in the correct order and understanding that AND requires all parts to be true. Watch for: Students forgetting to apply NOT operators or misunderstanding the requirement that AND needs all conditions true.

Question 6

A game AI checks isEnemyVisible and isHealthLow each turn:

if (isEnemyVisible || isHealthLow)
  alert = true
else
  alert = false

for turn from 1 to 5
  if (isEnemyVisible && isHealthLow)
    mode = "PANIC"

Which Boolean expression evaluates to true when isEnemyVisible is false and isHealthLow is true?

  1. isEnemyVisible && isHealthLow
  2. !(isEnemyVisible || isHealthLow)
  3. isEnemyVisible || isHealthLow (correct answer)
  4. !isEnemyVisible && !isHealthLow

Explanation: This question tests understanding of comparing Boolean expressions in AP Computer Science A, focusing on logical evaluation and selection/iteration concepts. Boolean expressions are logical statements that evaluate to true or false, guiding program flow through conditional constructs like if statements and loops. In the provided scenario, we need to find which expression evaluates to true when isEnemyVisible is false and isHealthLow is true. Choice C (isEnemyVisible || isHealthLow) is correct because it evaluates to false || true = true, as the OR operator returns true when at least one operand is true. Choice A is incorrect because it would evaluate to false && true = false, requiring both conditions to be true for the AND operation. To help students: Emphasize the difference between AND (both must be true) and OR (at least one must be true) operations. Watch for: Students confusing when AND versus OR operations yield true results.

Question 7

In a game update loop, isEnemyVisible and isHealthLow control actions:

while (isGameRunning)
  if (isEnemyVisible && !isHealthLow)
    action = "ATTACK"
  else if (isEnemyVisible && isHealthLow)
    action = "RETREAT"
  else
    action = "SEARCH"

What will be the output of the following code if isEnemyVisible is true and isHealthLow is false?

  1. action becomes "RETREAT"
  2. action becomes "ATTACK" (correct answer)
  3. action becomes "SEARCH"
  4. action becomes "RETREAT" then "SEARCH"

Explanation: This question tests understanding of comparing Boolean expressions in AP Computer Science A, focusing on logical evaluation and selection/iteration concepts. Boolean expressions are logical statements that evaluate to true or false, guiding program flow through conditional constructs like if statements and loops. In the provided scenario, expressions like isEnemyVisible && !isHealthLow are used to determine game actions, influencing the program's decision-making process. Choice B (action becomes "ATTACK") is correct because when isEnemyVisible is true and isHealthLow is false, the first condition (isEnemyVisible && !isHealthLow) evaluates to true && !false = true && true = true, causing action to be set to "ATTACK". Choice A is incorrect because "RETREAT" requires both isEnemyVisible and isHealthLow to be true, which doesn't match our given values. To help students: Emphasize tracing through conditional statements sequentially and evaluating each Boolean expression completely before moving to the next. Watch for: Students jumping to conclusions without carefully evaluating each condition in order.

Question 8

In a login system, hasValidCredentials and isAccountActive are checked:

if (hasValidCredentials && isAccountActive)
  access = "ALLOW"
else
  access = "DENY"

for attempts from 1 to 3
  if (!hasValidCredentials || !isAccountActive)
    lockCounter = lockCounter + 1

Which Boolean expression evaluates to true when hasValidCredentials is true and isAccountActive is false?

  1. hasValidCredentials && isAccountActive
  2. !hasValidCredentials && !isAccountActive
  3. !hasValidCredentials || !isAccountActive (correct answer)
  4. hasValidCredentials || isAccountActive

Explanation: This question tests understanding of comparing Boolean expressions in AP Computer Science A, focusing on logical evaluation and selection/iteration concepts. Boolean expressions are logical statements that evaluate to true or false, guiding program flow through conditional constructs like if statements and loops. In the provided scenario, expressions like hasValidCredentials && isAccountActive are used to determine access control, influencing the program's decision-making process. Choice C (!hasValidCredentials || !isAccountActive) is correct because when hasValidCredentials is true and isAccountActive is false, the expression becomes !true || !false = false || true = true, accurately reflecting the logical condition. Choice A is incorrect because it would evaluate to true && false = false, a common error when students don't carefully evaluate each part of the expression. To help students: Emphasize the importance of understanding logical operators (&&, ||, !) and practice evaluating expressions step-by-step with concrete true/false values. Watch for: Confusion between AND/OR operations and misunderstanding of the NOT operator's effect on Boolean values.

Question 9

Given the following Boolean expressions where a, b, and c are boolean variables:

Expression X: !a || (b && c) Expression Y: !(a && (!b || !c))

Which statement about the relationship between these expressions is correct?

  1. Expression X and Y are logically equivalent by De Morgan's laws and distributive properties (correct answer)
  2. Expression X is true only when Expression Y is false, making them logical complements
  3. Expression X is more restrictive than Y because it requires both b and c to be true when a is true
  4. Expression Y is always true when a is false, while Expression X depends on b and c values

Explanation: Using De Morgan's laws on Expression Y: !(a && (!b || !c)) = !a || !(!b || !c) = !a || (b && c), which is identical to Expression X. Choice B is incorrect because they're equivalent, not complements. Choice C misunderstands the logical structure. Choice D incorrectly states that Y is always true when a is false - both expressions behave the same way.

Question 10

A method contains these two conditional statements that determine access levels:

Statement 1: if (isAdmin || (isMember && accountActive && !suspended)) Statement 2: if (!((!isAdmin && !isMember) || (!isAdmin && !accountActive) || (!isAdmin && suspended)))

When will these statements produce different Boolean results?

  1. When isAdmin = false, isMember = true, accountActive = false, suspended = false
  2. When isAdmin = true, isMember = false, accountActive = false, suspended = true
  3. When isAdmin = false, isMember = true, accountActive = true, suspended = true
  4. These statements are logically equivalent and will never produce different results (correct answer)

Explanation: Statement 2 can be simplified using De Morgan's laws: !((!isAdmin && !isMember) || (!isAdmin && !accountActive) || (!isAdmin && suspended)) = !((!isAdmin && (!isMember || !accountActive || suspended))) = isAdmin || (isMember && accountActive && !suspended), which is identical to Statement 1. All the given test cases in choices A, B, and C will produce the same results for both statements.

Question 11

In a game scoring system, these conditions determine bonus points:

Condition A: (level > 5 && coins >= 100) || (level <= 5 && coins >= 200) Condition B: coins >= (level > 5 ? 100 : 200)

For which combination will Condition A evaluate to true but Condition B evaluate to false?

  1. level = 6, coins = 150 makes both conditions true since 150 >= 100
  2. level = 3, coins = 180 makes Condition A false and Condition B false
  3. level = 8, coins = 99 makes both conditions false since 99 < 100
  4. No combination exists where A is true and B is false since they are equivalent (correct answer)

Explanation: Condition B uses a ternary operator: if level > 5, then coins >= 100; otherwise coins >= 200. This is logically identical to Condition A. When level > 5, both require coins >= 100. When level <= 5, both require coins >= 200. Choice A correctly evaluates both as true but misses that we need A true and B false. Choice B incorrectly evaluates A (180 < 200 for level <= 5). Choice C correctly evaluates both as false but again misses the requirement.

Question 12

A delivery system uses these conditions to determine shipping eligibility:

Condition X: (weight <= 50 && domestic) || (weight <= 20 && !domestic) Condition Y: weight <= (domestic ? 50 : 20)

A programmer claims these conditions are equivalent. Which analysis of this claim is correct?

  1. The claim is false because when weight = 30 and domestic = false, X is false but Y is true
  2. The claim is false because when weight = 60 and domestic = true, X is true but Y is false
  3. The claim is true because both conditions implement the same logical requirements using different syntax (correct answer)
  4. The claim is false because Condition X allows international shipments that Condition Y prohibits

Explanation: Both conditions implement identical logic: if domestic, weight must be <= 50; if not domestic, weight must be <= 20. Condition Y uses ternary operator syntax while X uses boolean logic, but they're equivalent. For choice A: when weight=30, domestic=false, both conditions are false (30 > 20). For choice B: when weight=60, domestic=true, both conditions are false (60 > 50). Choice D is incorrect because both conditions treat international shipments identically.

Question 13

A programmer writes two Boolean expressions to validate user input:

Condition 1: (age >= 18 && hasLicense) || (age >= 16 && hasPermit && hasGuardian) Condition 2: age >= 16 && (hasLicense || (hasPermit && hasGuardian))

Which statement correctly compares these two conditions?

  1. Condition 1 is more restrictive because it requires age >= 18 for users with only a license (correct answer)
  2. Condition 2 is more restrictive because it always requires age >= 16 regardless of other factors
  3. The conditions are logically equivalent and will always produce the same result for any input
  4. Condition 1 is less restrictive because it allows users aged 16-17 with a license and no guardian

Explanation: Condition 1 requires age >= 18 for users who only have a license (no permit/guardian), while Condition 2 allows age >= 16 with just a license. For example, a 17-year-old with only a license would pass Condition 2 but fail Condition 1. Therefore, Condition 1 is more restrictive. Choice B is incorrect because both conditions have age requirements. Choice C is wrong because they're not equivalent. Choice D is backwards - Condition 1 is more restrictive, not less.

Question 14

A program validates user permissions with these expressions where admin, user, and guest are boolean variables:

Expression 1: admin || (user && !guest) Expression 2: !(!admin && (!user || guest))

Which scenario demonstrates that these expressions are NOT logically equivalent?

  1. admin = true, user = false, guest = true produces different results for both expressions
  2. admin = false, user = true, guest = true produces different results for both expressions
  3. admin = false, user = false, guest = false produces different results for both expressions
  4. These expressions are logically equivalent, so no scenario produces different results (correct answer)

Explanation: Expression 2 can be simplified using De Morgan's laws: !(!admin && (!user || guest)) = admin || !(!user || guest) = admin || (user && !guest), which is identical to Expression 1. For choice A: both expressions equal true. For choice B: both expressions equal false. For choice C: both expressions equal false. The expressions are logically equivalent.

Question 15

Consider these Boolean expressions used in a grading system where score is an integer:

Grade A: (score >= 90) && (score <= 100) Grade B: (score >= 80) && (score < 90) Grade C: (score >= 70) && (score < 80) Failing: score < 70

If a student's score satisfies the condition: (score >= 70) || (score < 90), which statement is necessarily true?

  1. The student received either a Grade A, Grade B, or Grade C, but definitely not failing
  2. The student could have any grade including failing, since the condition is always true (correct answer)
  3. The student received either Grade B, Grade C, or is failing, but definitely not Grade A
  4. The student received either Grade A or is failing, but definitely not Grade B or C

Explanation: The condition (score >= 70) || (score < 90) is always true for any integer score value. If score >= 70, the first part is true. If score < 70, then score is definitely < 90, so the second part is true. Since this condition is satisfied by all possible scores, it provides no information about which grade the student received. Choices A, C, and D all incorrectly assume the condition eliminates certain grade possibilities.