Implementing Selection and Iteration Algorithms - AP Computer Science A
Card 1 of 30
What does the logical operator && mean?
What does the logical operator && mean?
Tap to reveal answer
Logical AND. Returns true only when both operands are true.
Logical AND. Returns true only when both operands are true.
← Didn't Know|Knew It →
What is the purpose of an else statement in Java?
What is the purpose of an else statement in Java?
Tap to reveal answer
Executes code if the if condition is false. Alternative path when the if condition evaluates to false.
Executes code if the if condition is false. Alternative path when the if condition evaluates to false.
← Didn't Know|Knew It →
Identify the loop type: for(int i = 0; i < n; i++) {...}
Identify the loop type: for(int i = 0; i < n; i++) {...}
Tap to reveal answer
for loop. Uses initialization, condition, and increment/decrement in parentheses.
for loop. Uses initialization, condition, and increment/decrement in parentheses.
← Didn't Know|Knew It →
What does the break statement do in a loop?
What does the break statement do in a loop?
Tap to reveal answer
Terminates the loop immediately. Exits the loop completely and continues execution after the loop.
Terminates the loop immediately. Exits the loop completely and continues execution after the loop.
← Didn't Know|Knew It →
What is the syntax for a while loop in Java?
What is the syntax for a while loop in Java?
Tap to reveal answer
while (condition) { // statements }. Executes statements while the condition remains true.
while (condition) { // statements }. Executes statements while the condition remains true.
← Didn't Know|Knew It →
What keyword can skip the current iteration of a loop?
What keyword can skip the current iteration of a loop?
Tap to reveal answer
continue. Skips remaining statements in current iteration and moves to next iteration.
continue. Skips remaining statements in current iteration and moves to next iteration.
← Didn't Know|Knew It →
Which loop runs at least once: while or do-while?
Which loop runs at least once: while or do-while?
Tap to reveal answer
do-while loop. Checks condition after executing the body, guaranteeing at least one execution.
do-while loop. Checks condition after executing the body, guaranteeing at least one execution.
← Didn't Know|Knew It →
What is the primary use of a switch statement?
What is the primary use of a switch statement?
Tap to reveal answer
To execute code based on a variable's value. Provides multi-way branching based on variable values instead of if-else chains.
To execute code based on a variable's value. Provides multi-way branching based on variable values instead of if-else chains.
← Didn't Know|Knew It →
What does a case label in a switch statement require?
What does a case label in a switch statement require?
Tap to reveal answer
A constant expression. Must be a compile-time constant like literal or final variable.
A constant expression. Must be a compile-time constant like literal or final variable.
← Didn't Know|Knew It →
What is the default case in a switch statement for?
What is the default case in a switch statement for?
Tap to reveal answer
Executes if no case matches. Optional catch-all case when no other cases match the value.
Executes if no case matches. Optional catch-all case when no other cases match the value.
← Didn't Know|Knew It →
Identify the error: while(x == 10); { x++; }
Identify the error: while(x == 10); { x++; }
Tap to reveal answer
Semicolon after while condition is incorrect. Semicolon creates empty statement, making the loop body separate from while.
Semicolon after while condition is incorrect. Semicolon creates empty statement, making the loop body separate from while.
← Didn't Know|Knew It →
What is the precedence of logical operators: && and ||?
What is the precedence of logical operators: && and ||?
Tap to reveal answer
&& has higher precedence than ||. $&&$ is evaluated before $||$ in logical expressions.
&& has higher precedence than ||. $&&$ is evaluated before $||$ in logical expressions.
← Didn't Know|Knew It →
What does the logical operator || mean?
What does the logical operator || mean?
Tap to reveal answer
Logical OR. Returns true when at least one operand is true.
Logical OR. Returns true when at least one operand is true.
← Didn't Know|Knew It →
What is the output of: for(int i=0;i<3;i++){System.out.print(i);}
What is the output of: for(int i=0;i<3;i++){System.out.print(i);}
Tap to reveal answer
- Loop runs 3 times with $i$ values 0, 1, 2 printing consecutively.
- Loop runs 3 times with $i$ values 0, 1, 2 printing consecutively.
← Didn't Know|Knew It →
What is the output of: int x=0; if(x){x++;} System.out.print(x);
What is the output of: int x=0; if(x){x++;} System.out.print(x);
Tap to reveal answer
Compilation error. Integer cannot be used as boolean condition in Java if statements.
Compilation error. Integer cannot be used as boolean condition in Java if statements.
← Didn't Know|Knew It →
What is the purpose of a loop counter?
What is the purpose of a loop counter?
Tap to reveal answer
To track the number of iterations. Variable that keeps track of how many iterations have occurred.
To track the number of iterations. Variable that keeps track of how many iterations have occurred.
← Didn't Know|Knew It →
What keyword is used to exit a method in Java?
What keyword is used to exit a method in Java?
Tap to reveal answer
return. Immediately exits the current method and returns control to caller.
return. Immediately exits the current method and returns control to caller.
← Didn't Know|Knew It →
What is infinite loop?
What is infinite loop?
Tap to reveal answer
A loop that never ends. Condition never becomes false, causing continuous execution without termination.
A loop that never ends. Condition never becomes false, causing continuous execution without termination.
← Didn't Know|Knew It →
What is the primary use of a for loop?
What is the primary use of a for loop?
Tap to reveal answer
To iterate a block of code a known number of times. Best for counting loops where the number of iterations is predetermined.
To iterate a block of code a known number of times. Best for counting loops where the number of iterations is predetermined.
← Didn't Know|Knew It →
What is the output of: boolean b = (3 > 2); System.out.print(b);
What is the output of: boolean b = (3 > 2); System.out.print(b);
Tap to reveal answer
true. Boolean variable stores the result of the comparison expression.
true. Boolean variable stores the result of the comparison expression.
← Didn't Know|Knew It →
What is the output of: for(int i=5; i>0; i--) {System.out.print(i);}
What is the output of: for(int i=5; i>0; i--) {System.out.print(i);}
Tap to reveal answer
- Countdown loop printing decreasing values from 5 to 1.
- Countdown loop printing decreasing values from 5 to 1.
← Didn't Know|Knew It →
Identify the error: switch(x) { case 1: y=1; case 2: y=2; }
Identify the error: switch(x) { case 1: y=1; case 2: y=2; }
Tap to reveal answer
Missing break statements. Without breaks, execution falls through to subsequent cases.
Missing break statements. Without breaks, execution falls through to subsequent cases.
← Didn't Know|Knew It →
What is a condition in the context of control structures?
What is a condition in the context of control structures?
Tap to reveal answer
An expression that evaluates to true or false. Boolean expression that determines which code path to execute.
An expression that evaluates to true or false. Boolean expression that determines which code path to execute.
← Didn't Know|Knew It →
What is the output of: int x=0; while(x<3) {x++;} System.out.print(x);
What is the output of: int x=0; while(x<3) {x++;} System.out.print(x);
Tap to reveal answer
- Loop increments $x$ three times, final value is 3.
- Loop increments $x$ three times, final value is 3.
← Didn't Know|Knew It →
What is the output of: boolean b = (2 == 2); System.out.print(b);
What is the output of: boolean b = (2 == 2); System.out.print(b);
Tap to reveal answer
true. Equality comparison evaluates to true since both sides are equal.
true. Equality comparison evaluates to true since both sides are equal.
← Didn't Know|Knew It →
Identify the error: if(x = 5) {...}
Identify the error: if(x = 5) {...}
Tap to reveal answer
Assignment operator used instead of equality. Single $=$ assigns value; double $==$ compares for equality.
Assignment operator used instead of equality. Single $=$ assigns value; double $==$ compares for equality.
← Didn't Know|Knew It →
What do you call a loop inside another loop?
What do you call a loop inside another loop?
Tap to reveal answer
Nested loop. One loop placed inside the body of another loop structure.
Nested loop. One loop placed inside the body of another loop structure.
← Didn't Know|Knew It →
What is an iteration in the context of loops?
What is an iteration in the context of loops?
Tap to reveal answer
A single execution of the loop body. One complete pass through the loop body statements.
A single execution of the loop body. One complete pass through the loop body statements.
← Didn't Know|Knew It →
What is the precedence of logical operators: && and ||?
What is the precedence of logical operators: && and ||?
Tap to reveal answer
&& has higher precedence than ||. $&&$ is evaluated before $||$ in logical expressions.
&& has higher precedence than ||. $&&$ is evaluated before $||$ in logical expressions.
← Didn't Know|Knew It →
What keyword is used to exit a method in Java?
What keyword is used to exit a method in Java?
Tap to reveal answer
return. Immediately exits the current method and returns control to caller.
return. Immediately exits the current method and returns control to caller.
← Didn't Know|Knew It →