AP Computer Science a Flashcards: Algorithms With Selection And Repetition

Study Algorithms With Selection And Repetition in AP Computer Science a with focused flashcards that help you recognize the idea, recall the key rule, and apply it in practice-style prompts.

AP Computer Science a

Algorithms With Selection And Repetition

0 mastered0 still learning

0% Complete

QUESTION
1/ 80

What is the syntax for a switch statement in Java?

Tap card or press Space to flip

ANSWER

switch(expression) { case value: statements; break; }. Multi-way selection based on expression value.

How well did you know it?

Card 1 / 80

What this deck covers

This deck focuses on Algorithms With Selection And Repetition, giving you a quick way to review the definitions, rules, and examples that matter most for AP Computer Science a.

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 the syntax for a switch statement in Java?

Answer: switch(expression) { case value: statements; break; }. Multi-way selection based on expression value.

Flashcard 2: What keyword is used to define multiple selections in a switch statement?

Answer: case. Each case represents a possible match value.

Flashcard 3: What is an iteration in the context of loops?

Answer: A single execution of the loop body. One complete pass through the loop body.

Flashcard 4: What differentiates a for loop from a while loop?

Answer: Initialization, condition, and update in one line. For loop combines all control elements in header.

Flashcard 5: What is the syntax for a do-while loop in Java?

Answer: do { statements } while (condition);. Body executes first, then condition is checked.

Flashcard 6: Which loop structure is best for iterating a known number of times?

Answer: for loop. Compact syntax when iteration count is predetermined.

Flashcard 7: What keyword is used to exit a loop prematurely?

Answer: break. Immediately terminates loop execution.

Flashcard 8: What is the syntax for a basic if statement in Java?

Answer: if (condition) { statements }. Standard conditional statement structure in Java.

Flashcard 9: What is the syntax for a basic if statement in Java?

Answer: if (condition) { statements }. Standard conditional statement structure in Java.

Flashcard 10: Identify the operator used to compare equality in Java.

Answer: ==. Double equals compares values, single equals assigns.

Flashcard 11: What is the default case in a switch statement?

Answer: Executed if no case matches. Catches all unmatched values in switch statement.

Flashcard 12: Determine the output: int i = 0; do { System.out.print(i); } while (i > 0);

Answer:

  1. Executes once since condition checked after execution.

Flashcard 13: What is the purpose of a loop control variable?

Answer: To control the number of iterations of the loop. Manages how many times the loop body executes.

Flashcard 14: Which loop structure is best for iterating a known number of times?

Answer: for loop. Compact syntax when iteration count is predetermined.

Flashcard 15: How many times will this loop execute? for (int i = 0; i < 5; i++)

Answer: 5 times. Loop runs while i < 5: values 0, 1, 2, 3, 4.

Flashcard 16: What is the significance of the loop condition?

Answer: Determines when the loop stops. Controls whether loop continues or terminates.

Flashcard 17: What is the purpose of a loop control variable?

Answer: To control the number of iterations of the loop. Manages how many times the loop body executes.

Flashcard 18: Find the error: for (int i = 0; i < 10; i--)

Answer: i-- should be i++. Decrement creates infinite loop since i never reaches 10.

Flashcard 19: Identify the keyword used for creating a loop in Java.

Answer: for, while, or do-while. These are the three main loop keywords in Java.

Flashcard 20: Identify the operator used to compare equality in Java.

Answer: ==. Double equals compares values, single equals assigns.

Flashcard 21: What is an infinite loop?

Answer: A loop that never terminates. Occurs when loop condition never becomes false.

Flashcard 22: What is the result of the expression: 4 >= 4?

Answer: true. Greater than or equal to includes equality.

Flashcard 23: Which loop condition form ensures a loop runs zero or more times?

Answer: while loop. Condition checked before execution, may not run at all.

Flashcard 24: What is the syntax for a switch statement in Java?

Answer: switch(expression) { case value: statements; break; }. Multi-way selection based on expression value.

Flashcard 25: Determine the output: int x = 0; while (x < 2) { x++; } System.out.print(x);

Answer:

  1. Loop increments x twice (0→1, 1→2), then x printed.

Flashcard 26: Which loop always executes its block at least once?

Answer: do-while loop. Condition is checked after execution, guaranteeing one run.

Flashcard 27: What differentiates a for loop from a while loop?

Answer: Initialization, condition, and update in one line. For loop combines all control elements in header.

Flashcard 28: What is an infinite loop?

Answer: A loop that never terminates. Occurs when loop condition never becomes false.

Flashcard 29: Identify the error: for (int i = 0; i < 5; i++) { System.out.print(i); }

Answer: No error. Syntax is correct for standard for loop.

Flashcard 30: What is the result of: boolean b = (2 < 3) && (3 > 2);

Answer: true. Both conditions are true, AND returns true.

Flashcard 31: How is a for loop typically structured in Java?

Answer: for (initialization; condition; update) { statements }. Three parts control initialization, termination, and increment.

Flashcard 32: What is the purpose of using else after if?

Answer: To execute code when the if condition is false. Provides alternative path when condition is false.

Flashcard 33: Identify the keyword that ends a switch case.

Answer: break. Prevents fall-through to subsequent cases.

Flashcard 34: Determine the output: int i = 0; do { System.out.print(i); } while (i > 0);

Answer:

  1. Executes once since condition checked after execution.

Flashcard 35: Which loop condition form ensures a loop runs zero or more times?

Answer: while loop. Condition checked before execution, may not run at all.

Flashcard 36: What is the significance of the loop condition?

Answer: Determines when the loop stops. Controls whether loop continues or terminates.

Flashcard 37: Determine the output: int x = 5; if (x < 5) { x--; } System.out.print(x);

Answer:

  1. Condition is false, so x remains unchanged.

Flashcard 38: Identify the error: if (x = 5) { ... }

Answer: Use == instead of =. Single equals is assignment, not comparison.

Flashcard 39: Identify the error: for (int i = 0; i < 5; i++) { System.out.print(i); }

Answer: No error. Syntax is correct for standard for loop.

Flashcard 40: What is the purpose of a selection statement in programming?

Answer: To execute code based on a condition. Allows programs to make decisions and branch execution paths.

Flashcard 41: What does the continue statement do in a loop?

Answer: Skips the current iteration and continues with the next. Jumps to next iteration without executing remaining code.

Flashcard 42: Identify the error: while (true); { System.out.print("Loop"); }

Answer: Semicolon after true creates an infinite loop. Empty statement after while creates infinite loop.

Flashcard 43: What is an iteration in the context of loops?

Answer: A single execution of the loop body. One complete pass through the loop body.

Flashcard 44: Identify the keyword that ends a switch case.

Answer: break. Prevents fall-through to subsequent cases.

Flashcard 45: What are nested loops?

Answer: Loops within loops. One loop contained inside another loop's body.

Flashcard 46: Which loop always executes its block at least once?

Answer: do-while loop. Condition is checked after execution, guaranteeing one run.

Flashcard 47: What is the result of 5 % 2?

Answer:

  1. Modulo operator returns remainder of division.

Flashcard 48: Find the error: for (int i = 0; i < 10; i--)

Answer: i-- should be i++. Decrement creates infinite loop since i never reaches 10.

Flashcard 49: What is the default case in a switch statement?

Answer: Executed if no case matches. Catches all unmatched values in switch statement.

Flashcard 50: What keyword is used to define multiple selections in a switch statement?

Answer: case. Each case represents a possible match value.

Flashcard 51: What is the result of the expression: 4 >= 4?

Answer: true. Greater than or equal to includes equality.

Flashcard 52: How many times will this loop execute? for (int i = 0; i < 5; i++)

Answer: 5 times. Loop runs while i < 5: values 0, 1, 2, 3, 4.

Flashcard 53: What is the purpose of the else if statement?

Answer: To test multiple conditions in sequence. Chains conditions for multiple decision paths.

Flashcard 54: How is a for loop typically structured in Java?

Answer: for (initialization; condition; update) { statements }. Three parts control initialization, termination, and increment.

Flashcard 55: What does the continue statement do in a loop?

Answer: Skips the current iteration and continues with the next. Jumps to next iteration without executing remaining code.

Flashcard 56: What is the output of: if (false) { System.out.print("X"); }

Answer: No output. False condition means if block doesn't execute.

Flashcard 57: Identify the error: if (x = 5) { ... }

Answer: Use == instead of =. Single equals is assignment, not comparison.

Flashcard 58: What is the result of 5 % 2?

Answer:

  1. Modulo operator returns remainder of division.

Flashcard 59: What happens if break is omitted in a switch case?

Answer: Fall-through to next case occurs. Code continues executing into subsequent cases.

Flashcard 60: What is the result of: boolean b = (2 < 3) && (3 > 2);

Answer: true. Both conditions are true, AND returns true.

Flashcard 61: Determine the output: int x = 5; if (x < 5) { x--; } System.out.print(x);

Answer:

  1. Condition is false, so x remains unchanged.

Flashcard 62: Which statement is used to skip an iteration in a loop?

Answer: continue. Bypasses remaining code in current iteration.

Flashcard 63: What is the purpose of using else after if?

Answer: To execute code when the if condition is false. Provides alternative path when condition is false.

Flashcard 64: Identify the error: switch (x) { case 1: System.out.print(1); }

Answer: Missing break statement. Without break, execution continues to next case.

Flashcard 65: Determine the output: int x = 0; while (x < 2) { x++; } System.out.print(x);

Answer:

  1. Loop increments x twice (0→1, 1→2), then x printed.

Flashcard 66: Identify the error: switch (x) { case 1: System.out.print(1); }

Answer: Missing break statement. Without break, execution continues to next case.

Flashcard 67: What is the output of: if (true) { System.out.print("A"); } else { System.out.print("B"); }

Answer: A. True condition executes the if block.

Flashcard 68: Identify the error: while (true); { System.out.print("Loop"); }

Answer: Semicolon after true creates an infinite loop. Empty statement after while creates infinite loop.

Flashcard 69: What does an if-else statement do?

Answer: Executes code blocks based on condition being true or false. Provides branching logic for conditional execution.

Flashcard 70: What happens if break is omitted in a switch case?

Answer: Fall-through to next case occurs. Code continues executing into subsequent cases.

Flashcard 71: What is the purpose of the else if statement?

Answer: To test multiple conditions in sequence. Chains conditions for multiple decision paths.

Flashcard 72: Identify the keyword used for creating a loop in Java.

Answer: for, while, or do-while. These are the three main loop keywords in Java.

Flashcard 73: What is the purpose of a selection statement in programming?

Answer: To execute code based on a condition. Allows programs to make decisions and branch execution paths.

Flashcard 74: Which statement is used to skip an iteration in a loop?

Answer: continue. Bypasses remaining code in current iteration.

Flashcard 75: What is the syntax for a do-while loop in Java?

Answer: do { statements } while (condition);. Body executes first, then condition is checked.

Flashcard 76: What does an if-else statement do?

Answer: Executes code blocks based on condition being true or false. Provides branching logic for conditional execution.

Flashcard 77: What keyword is used to exit a loop prematurely?

Answer: break. Immediately terminates loop execution.

Flashcard 78: What are nested loops?

Answer: Loops within loops. One loop contained inside another loop's body.

Flashcard 79: What is the output of: if (false) { System.out.print("X"); }

Answer: No output. False condition means if block doesn't execute.

Flashcard 80: What is the output of: if (true) { System.out.print("A"); } else { System.out.print("B"); }

Answer: A. True condition executes the if block.