AP Computer Science a Flashcards: Implementing Selection And Iteration Algorithms

Study Implementing Selection And Iteration Algorithms 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

Implementing Selection And Iteration Algorithms

0 mastered0 still learning

0% Complete

QUESTION
1/ 72

What is an iteration in the context of loops?

Tap card or press Space to flip

ANSWER

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

How well did you know it?

Card 1 / 72

What this deck covers

This deck focuses on Implementing Selection And Iteration Algorithms, 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 an iteration in the context of loops?

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

Flashcard 2: What does a case label in a switch statement require?

Answer: A constant expression. Must be a compile-time constant like literal or final variable.

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

Answer: Assignment operator used instead of equality. Single == assigns value; double ==== compares for equality.

Flashcard 4: Which loop runs at least once: while or do-while?

Answer: do-while loop. Checks condition after executing the body, guaranteeing at least one execution.

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

Answer: do { // statements } while (condition);. Executes body first, then checks condition; semicolon required after while.

Flashcard 6: What is the output of: for(int i=0; i<2; i++) {for(int j=0; j<2; j++) {System.out.print("*");}}

Answer: ****. Nested loops: outer runs 2 times, inner runs 2 times each.

Flashcard 7: What is the primary use of a switch statement?

Answer: To execute code based on a variable's value. Provides multi-way branching based on variable values instead of if-else chains.

Flashcard 8: What is the syntax for a while loop in Java?

Answer: while (condition) { // statements }. Executes statements while the condition remains true.

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

Answer: Assignment operator used instead of equality. Single == assigns value; double ==== compares for equality.

Flashcard 10: What is the output of: boolean b = (2 == 2); System.out.print(b);

Answer: true. Equality comparison evaluates to true since both sides are equal.

Flashcard 11: What is the result of the expression: !true?

Answer: false. NOT operation: inverts the boolean value from true to false.

Flashcard 12: What is the purpose of an else statement in Java?

Answer: Executes code if the if condition is false. Alternative path when the if condition evaluates to false.

Flashcard 13: What is the precedence of logical operators: && and ||?

Answer: && has higher precedence than ||. &&\&\& is evaluated before || in logical expressions.

Flashcard 14: Identify the error: for(int i=0; i<5; i--) {...}

Answer: Loop condition will never be false. Decrementing ii makes it more negative, never reaching the termination condition.

Flashcard 15: What does the expression (a == b) evaluate to?

Answer: true if a is equal to b, else false. Equality operator returns boolean value based on comparison result.

Flashcard 16: What is infinite loop?

Answer: A loop that never ends. Condition never becomes false, causing continuous execution without termination.

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

Answer: Executes if no case matches. Optional catch-all case when no other cases match the value.

Flashcard 18: What does the logical operator && mean?

Answer: Logical AND. Returns true only when both operands are true.

Flashcard 19: What is the syntax for an if statement in Java?

Answer: if (condition) { // statements }. Standard conditional statement structure with condition in parentheses and code in braces.

Flashcard 20: What is the output of: do {i++;} while(i<0); for i=0?

Answer: i=1. Body executes once before condition check, incrementing ii from 0 to 1.

Flashcard 21: Identify the loop type: for(int i = 0; i < n; i++) {...}

Answer: for loop. Uses initialization, condition, and increment/decrement in parentheses.

Flashcard 22: What does the break statement do in a loop?

Answer: Terminates the loop immediately. Exits the loop completely and continues execution after the loop.

Flashcard 23: What keyword is used to exit a method in Java?

Answer: return. Immediately exits the current method and returns control to caller.

Flashcard 24: How many times does a nested loop run: for(i=0;i<3;i++) for(j=0;j<2;j++)?

Answer: 6 times. Outer loop runs 3 times, inner loop runs 2 times each: 3×2=63 \times 2 = 6.

Flashcard 25: What is the output of: int x=0; while(x<3) {x++;} System.out.print(x);

Answer:

  1. Loop increments xx three times, final value is 3.

Flashcard 26: What is the output of: for(int i=5; i>0; i--) {System.out.print(i);}

Answer:

  1. Countdown loop printing decreasing values from 5 to 1.

Flashcard 27: What is the output of: for(int i=0;i<3;i++){System.out.print(i);}

Answer:

  1. Loop runs 3 times with ii values 0, 1, 2 printing consecutively.

Flashcard 28: Identify the error: switch(x) { case 1: y=1; case 2: y=2; }

Answer: Missing break statements. Without breaks, execution falls through to subsequent cases.

Flashcard 29: What does the break statement do in a loop?

Answer: Terminates the loop immediately. Exits the loop completely and continues execution after the loop.

Flashcard 30: What is the result of the expression: true && false?

Answer: false. AND operation: true only when both operands are true.

Flashcard 31: Identify the error: while(x == 10); { x++; }

Answer: Semicolon after while condition is incorrect. Semicolon creates empty statement, making the loop body separate from while.

Flashcard 32: What does a case label in a switch statement require?

Answer: A constant expression. Must be a compile-time constant like literal or final variable.

Flashcard 33: What is the result of the expression: true || false?

Answer: true. OR operation: true when at least one operand is true.

Flashcard 34: Identify the error: for(int i=0; i<5; i--) {...}

Answer: Loop condition will never be false. Decrementing ii makes it more negative, never reaching the termination condition.

Flashcard 35: What is the output of: boolean b = (3 > 2); System.out.print(b);

Answer: true. Boolean variable stores the result of the comparison expression.

Flashcard 36: What is the precedence of logical operators: && and ||?

Answer: && has higher precedence than ||. &&\&\& is evaluated before || in logical expressions.

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

Answer: Executes if no case matches. Optional catch-all case when no other cases match the value.

Flashcard 38: What do you call a loop inside another loop?

Answer: Nested loop. One loop placed inside the body of another loop structure.

Flashcard 39: What is the output of: if(1 < 2) {System.out.print("A");} else {System.out.print("B");}

Answer: A. Condition 1<21 < 2 is true, so executes the if branch.

Flashcard 40: What is the output of: for(int i=0;i<3;i++){System.out.print(i);}

Answer:

  1. Loop runs 3 times with ii values 0, 1, 2 printing consecutively.

Flashcard 41: What is the output of: int x=0; if(x){x++;} System.out.print(x);

Answer: Compilation error. Integer cannot be used as boolean condition in Java if statements.

Flashcard 42: What does the logical operator || mean?

Answer: Logical OR. Returns true when at least one operand is true.

Flashcard 43: What is a condition in the context of control structures?

Answer: An expression that evaluates to true or false. Boolean expression that determines which code path to execute.

Flashcard 44: What does the expression (a == b) evaluate to?

Answer: true if a is equal to b, else false. Equality operator returns boolean value based on comparison result.

Flashcard 45: What is the output of: for(int i=0; i<2; i++) {for(int j=0; j<2; j++) {System.out.print("*");}}

Answer: ****. Nested loops: outer runs 2 times, inner runs 2 times each.

Flashcard 46: What is the output of: int x=0; if(x){x++;} System.out.print(x);

Answer: Compilation error. Integer cannot be used as boolean condition in Java if statements.

Flashcard 47: What keyword can skip the current iteration of a loop?

Answer: continue. Skips remaining statements in current iteration and moves to next iteration.

Flashcard 48: What is a condition in the context of control structures?

Answer: An expression that evaluates to true or false. Boolean expression that determines which code path to execute.

Flashcard 49: What is the output of: boolean b = (2 == 2); System.out.print(b);

Answer: true. Equality comparison evaluates to true since both sides are equal.

Flashcard 50: Which loop runs at least once: while or do-while?

Answer: do-while loop. Checks condition after executing the body, guaranteeing at least one execution.

Flashcard 51: What keyword can skip the current iteration of a loop?

Answer: continue. Skips remaining statements in current iteration and moves to next iteration.

Flashcard 52: What is the syntax for a while loop in Java?

Answer: while (condition) { // statements }. Executes statements while the condition remains true.

Flashcard 53: What is the output of: for(int i=5; i>0; i--) {System.out.print(i);}

Answer:

  1. Countdown loop printing decreasing values from 5 to 1.

Flashcard 54: What is the output of: int x=0; while(x<3) {x++;} System.out.print(x);

Answer:

  1. Loop increments xx three times, final value is 3.

Flashcard 55: What is the primary use of a for loop?

Answer: To iterate a block of code a known number of times. Best for counting loops where the number of iterations is predetermined.

Flashcard 56: What does the logical operator || mean?

Answer: Logical OR. Returns true when at least one operand is true.

Flashcard 57: What is the purpose of a loop counter?

Answer: To track the number of iterations. Variable that keeps track of how many iterations have occurred.

Flashcard 58: What is the output of: if(1 < 2) {System.out.print("A");} else {System.out.print("B");}

Answer: A. Condition 1<21 < 2 is true, so executes the if branch.

Flashcard 59: What is infinite loop?

Answer: A loop that never ends. Condition never becomes false, causing continuous execution without termination.

Flashcard 60: What is the output of: boolean b = (3 > 2); System.out.print(b);

Answer: true. Boolean variable stores the result of the comparison expression.

Flashcard 61: How many times does a nested loop run: for(i=0;i<3;i++) for(j=0;j<2;j++)?

Answer: 6 times. Outer loop runs 3 times, inner loop runs 2 times each: 3×2=63 \times 2 = 6.

Flashcard 62: What do you call a loop inside another loop?

Answer: Nested loop. One loop placed inside the body of another loop structure.

Flashcard 63: What is the purpose of a loop counter?

Answer: To track the number of iterations. Variable that keeps track of how many iterations have occurred.

Flashcard 64: What is the purpose of an else statement in Java?

Answer: Executes code if the if condition is false. Alternative path when the if condition evaluates to false.

Flashcard 65: Identify the error: switch(x) { case 1: y=1; case 2: y=2; }

Answer: Missing break statements. Without breaks, execution falls through to subsequent cases.

Flashcard 66: What does the logical operator && mean?

Answer: Logical AND. Returns true only when both operands are true.

Flashcard 67: What is the primary use of a switch statement?

Answer: To execute code based on a variable's value. Provides multi-way branching based on variable values instead of if-else chains.

Flashcard 68: What keyword is used to exit a method in Java?

Answer: return. Immediately exits the current method and returns control to caller.

Flashcard 69: What is the output of: do {i++;} while(i<0); for i=0?

Answer: i=1. Body executes once before condition check, incrementing ii from 0 to 1.

Flashcard 70: Identify the loop type: for(int i = 0; i < n; i++) {...}

Answer: for loop. Uses initialization, condition, and increment/decrement in parentheses.

Flashcard 71: Identify the error: while(x == 10); { x++; }

Answer: Semicolon after while condition is incorrect. Semicolon creates empty statement, making the loop body separate from while.

Flashcard 72: What is the primary use of a for loop?

Answer: To iterate a block of code a known number of times. Best for counting loops where the number of iterations is predetermined.