AP Computer Science Principles Flashcards: Conditionals

Study Conditionals in AP Computer Science Principles with focused flashcards that help you recognize the idea, recall the key rule, and apply it in practice-style prompts.

AP Computer Science Principles

Conditionals

0 mastered0 still learning

0% Complete

QUESTION
1/ 70

What is short-circuit evaluation in conditional logic?

Tap card or press Space to flip

ANSWER

Evaluation stops once the result is determined. Optimizes performance by avoiding unnecessary evaluations.

How well did you know it?

Card 1 / 70

What this deck covers

This deck focuses on Conditionals, giving you a quick way to review the definitions, rules, and examples that matter most for AP Computer Science Principles.

How to use these flashcards

Work through these flashcards in short sessions. Try to answer each prompt before flipping the card, then revisit any cards you miss until the explanation feels automatic.

All flashcards

Flashcard 1: What is short-circuit evaluation in conditional logic?

Answer: Evaluation stops once the result is determined. Optimizes performance by avoiding unnecessary evaluations.

Flashcard 2: Which keyword is used to create an alternative condition in Java?

Answer: else. Provides an alternative path when the if condition is false.

Flashcard 3: What keyword marks the end of an if-else statement block?

Answer: There is no specific keyword; it's marked by braces. Java uses braces to define block boundaries, not keywords.

Flashcard 4: Identify the error: if (x > 0) { return true; } return false;

Answer: No error; the logic is correct. Valid pattern: if returns early, else is implicit.

Flashcard 5: How is a conditional expression structured in Java?

Answer: condition ? trueExpression : falseExpression. Ternary operator provides a compact if-else alternative.

Flashcard 6: What does an else if statement allow in conditional logic?

Answer: Multiple conditions to be checked sequentially. Enables testing additional conditions when previous ones fail.

Flashcard 7: What is the significance of nesting if-else statements?

Answer: Allows complex conditional logic. Enables sophisticated decision trees and branching logic.

Flashcard 8: What is the significance of nesting if-else statements?

Answer: Allows complex conditional logic. Enables sophisticated decision trees and branching logic.

Flashcard 9: Which operator is used for logical AND in Java?

Answer: &&. Returns true only when both operands are true.

Flashcard 10: Identify the error: if (x = 5) { return true; }

Answer: Replace '=' with '==' for comparison. Assignment operator '=' assigns value; '==' compares values.

Flashcard 11: What is the purpose of an if statement in programming?

Answer: To execute code based on a condition being true. Conditionals control program flow based on boolean evaluations.

Flashcard 12: Identify the error: if (x > 0) { return true; } return false;

Answer: No error; the logic is correct. Valid pattern: if returns early, else is implicit.

Flashcard 13: What is the default action if no conditions in if-else are met?

Answer: Execute the else block if present. Else provides fallback behavior for unmatched conditions.

Flashcard 14: How do you check if two variables x and y are equal?

Answer: x == y. Double equals performs comparison, not assignment.

Flashcard 15: What does the logical NOT operator (!) do?

Answer: Inverts the truth value of a boolean expression. Flips true to false and false to true.

Flashcard 16: What does a conditional statement evaluate to?

Answer: A boolean value (true or false). All conditional expressions result in boolean values.

Flashcard 17: How do you denote 'not equal to' in Java?

Answer: !=. Comparison operator that returns true when values differ.

Flashcard 18: What is the outcome if the condition in a ternary operator is false?

Answer: The falseExpression is executed. Ternary operator returns the false branch value.

Flashcard 19: Identify the error: if (a == b) { return a } else { return b }

Answer: Missing semicolons after 'return a' and 'return b'. Return statements require semicolons to terminate properly.

Flashcard 20: Which operator is used for logical OR in Java?

Answer: ||. Returns true when at least one operand is true.

Flashcard 21: What is the outcome if the condition in a ternary operator is false?

Answer: The falseExpression is executed. Ternary operator returns the false branch value.

Flashcard 22: When is a switch statement preferred over multiple if-else?

Answer: When evaluating a single variable against constants. Switch is cleaner for testing one variable against many values.

Flashcard 23: Identify the error: if (x = 10) { y = 5; }

Answer: Replace '=' with '==' for comparison. Assignment in condition should be comparison instead.

Flashcard 24: Identify the error: if (x = 5) { return true; }

Answer: Replace '=' with '==' for comparison. Assignment operator '=' assigns value; '==' compares values.

Flashcard 25: What does the logical NOT operator (!) do?

Answer: Inverts the truth value of a boolean expression. Flips true to false and false to true.

Flashcard 26: Identify the error: if (x > 10) else { return false; }

Answer: Remove 'else' or associate it with a preceding 'if'. Every 'else' must be paired with a preceding 'if' statement.

Flashcard 27: How is a conditional expression structured in Java?

Answer: condition ? trueExpression : falseExpression. Ternary operator provides a compact if-else alternative.

Flashcard 28: Identify the error: if (a == b) { return a } else { return b }

Answer: Missing semicolons after 'return a' and 'return b'. Return statements require semicolons to terminate properly.

Flashcard 29: What is the result of an else block when the if condition is true?

Answer: The else block is skipped. True conditions bypass else blocks entirely.

Flashcard 30: How can you check for both conditions A and B being true?

Answer: A && B. AND requires both conditions to be true simultaneously.

Flashcard 31: Which operator is used for logical AND in Java?

Answer: &&. Returns true only when both operands are true.

Flashcard 32: Which keyword is used to break out of a switch statement?

Answer: break. Prevents fall-through to subsequent case statements.

Flashcard 33: When is a switch statement preferred over multiple if-else?

Answer: When evaluating a single variable against constants. Switch is cleaner for testing one variable against many values.

Flashcard 34: What does '==' operator check in Java?

Answer: Equality of two values. Comparison operator that tests for value equivalence.

Flashcard 35: Identify the error: if (x > 10) else { return false; }

Answer: Remove 'else' or associate it with a preceding 'if'. Every 'else' must be paired with a preceding 'if' statement.

Flashcard 36: What does an else if statement allow in conditional logic?

Answer: Multiple conditions to be checked sequentially. Enables testing additional conditions when previous ones fail.

Flashcard 37: Which keyword allows an action when all if conditions are false?

Answer: else. Catches all cases where if conditions evaluate to false.

Flashcard 38: In Java, what is the default case in a switch statement?

Answer: Executed if no other case matches. Handles cases not explicitly covered by other cases.

Flashcard 39: What is the purpose of nested if statements?

Answer: To evaluate multiple conditions within each other. Inner conditions depend on outer conditions being true.

Flashcard 40: Which operator is used for logical OR in Java?

Answer: ||. Returns true when at least one operand is true.

Flashcard 41: What is the default action if no conditions in if-else are met?

Answer: Execute the else block if present. Else provides fallback behavior for unmatched conditions.

Flashcard 42: What type of value must an if statement condition evaluate to?

Answer: Boolean. Conditions must resolve to true or false values.

Flashcard 43: Identify the error: if (x < 0) { return negative; }

Answer: Ensure 'negative' is a defined variable or value. Undefined variables cause compilation errors.

Flashcard 44: Which keyword is used to create an alternative condition in Java?

Answer: else. Provides an alternative path when the if condition is false.

Flashcard 45: Identify the error: if (x < 0) { return negative; }

Answer: Ensure 'negative' is a defined variable or value. Undefined variables cause compilation errors.

Flashcard 46: What is the result of an else block when the if condition is true?

Answer: The else block is skipped. True conditions bypass else blocks entirely.

Flashcard 47: What is the purpose of nested if statements?

Answer: To evaluate multiple conditions within each other. Inner conditions depend on outer conditions being true.

Flashcard 48: What is a compound conditional statement?

Answer: Combines multiple conditions with logical operators. Uses AND, OR, or NOT to link multiple boolean expressions.

Flashcard 49: Which keyword allows an action when all if conditions are false?

Answer: else. Catches all cases where if conditions evaluate to false.

Flashcard 50: What keyword marks the end of an if-else statement block?

Answer: There is no specific keyword; it's marked by braces. Java uses braces to define block boundaries, not keywords.

Flashcard 51: How do you check if two variables x and y are equal?

Answer: x == y. Double equals performs comparison, not assignment.

Flashcard 52: Identify the error: if (x < 10); return x;

Answer: Remove the semicolon after the if condition. Empty statement creates unintended logic flow.

Flashcard 53: What is the result of a condition that evaluates to false?

Answer: The code block is not executed. False conditions cause the associated code block to be skipped.

Flashcard 54: What type of value must an if statement condition evaluate to?

Answer: Boolean. Conditions must resolve to true or false values.

Flashcard 55: What does '==' operator check in Java?

Answer: Equality of two values. Comparison operator that tests for value equivalence.

Flashcard 56: What is the result of a condition that evaluates to false?

Answer: The code block is not executed. False conditions cause the associated code block to be skipped.

Flashcard 57: What is a compound conditional statement?

Answer: Combines multiple conditions with logical operators. Uses AND, OR, or NOT to link multiple boolean expressions.

Flashcard 58: Identify the error: if (x < 7) { return true }

Answer: Missing semicolon after 'return true'. All statements in Java must end with a semicolon.

Flashcard 59: How can you check for both conditions A and B being true?

Answer: A && B. AND requires both conditions to be true simultaneously.

Flashcard 60: What is the purpose of an if statement in programming?

Answer: To execute code based on a condition being true. Conditionals control program flow based on boolean evaluations.

Flashcard 61: Identify the error: if (x = 10) { y = 5; }

Answer: Replace '=' with '==' for comparison. Assignment in condition should be comparison instead.

Flashcard 62: What is short-circuit evaluation in conditional logic?

Answer: Evaluation stops once the result is determined. Optimizes performance by avoiding unnecessary evaluations.

Flashcard 63: How do you check if either condition A or B is true?

Answer: A || B. OR returns true if any condition is satisfied.

Flashcard 64: Identify the error: if (x < 10); return x;

Answer: Remove the semicolon after the if condition. Empty statement creates unintended logic flow.

Flashcard 65: In Java, what is the default case in a switch statement?

Answer: Executed if no other case matches. Handles cases not explicitly covered by other cases.

Flashcard 66: How do you denote 'not equal to' in Java?

Answer: !=. Comparison operator that returns true when values differ.

Flashcard 67: What does a conditional statement evaluate to?

Answer: A boolean value (true or false). All conditional expressions result in boolean values.

Flashcard 68: Identify the error: if (x < 7) { return true }

Answer: Missing semicolon after 'return true'. All statements in Java must end with a semicolon.

Flashcard 69: Which keyword is used to break out of a switch statement?

Answer: break. Prevents fall-through to subsequent case statements.

Flashcard 70: How do you check if either condition A or B is true?

Answer: A || B. OR returns true if any condition is satisfied.