Algorithms with Selection and Repetition - AP Computer Science A
Card 1 of 30
Which statement is used to skip an iteration in a loop?
Which statement is used to skip an iteration in a loop?
Tap to reveal answer
continue. Bypasses remaining code in current iteration.
continue. Bypasses remaining code in current iteration.
← Didn't Know|Knew It →
What is the output of: if (false) { System.out.print("X"); }
What is the output of: if (false) { System.out.print("X"); }
Tap to reveal answer
No output. False condition means if block doesn't execute.
No output. False condition means if block doesn't execute.
← Didn't Know|Knew It →
What is the significance of the loop condition?
What is the significance of the loop condition?
Tap to reveal answer
Determines when the loop stops. Controls whether loop continues or terminates.
Determines when the loop stops. Controls whether loop continues or terminates.
← Didn't Know|Knew It →
Which loop always executes its block at least once?
Which loop always executes its block at least once?
Tap to reveal answer
do-while loop. Condition is checked after execution, guaranteeing one run.
do-while loop. Condition is checked after execution, guaranteeing one run.
← Didn't Know|Knew It →
Identify the error: for (int i = 0; i < 5; i++) { System.out.print(i); }
Identify the error: for (int i = 0; i < 5; i++) { System.out.print(i); }
Tap to reveal answer
No error. Syntax is correct for standard for loop.
No error. Syntax is correct for standard for loop.
← Didn't Know|Knew It →
What differentiates a for loop from a while loop?
What differentiates a for loop from a while loop?
Tap to reveal answer
Initialization, condition, and update in one line. For loop combines all control elements in header.
Initialization, condition, and update in one line. For loop combines all control elements in header.
← Didn't Know|Knew It →
What is the result of: boolean b = (2 < 3) && (3 > 2);
What is the result of: boolean b = (2 < 3) && (3 > 2);
Tap to reveal answer
true. Both conditions are true, AND returns true.
true. Both conditions are true, AND returns true.
← Didn't Know|Knew It →
Determine the output: int x = 5; if (x < 5) { x--; } System.out.print(x);
Determine the output: int x = 5; if (x < 5) { x--; } System.out.print(x);
Tap to reveal answer
- Condition is false, so x remains unchanged.
- Condition is false, so x remains unchanged.
← 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.
A single execution of the loop body. One complete pass through the loop body.
← Didn't Know|Knew It →
What is the result of the expression: 4 >= 4?
What is the result of the expression: 4 >= 4?
Tap to reveal answer
true. Greater than or equal to includes equality.
true. Greater than or equal to includes equality.
← Didn't Know|Knew It →
What is the purpose of a selection statement in programming?
What is the purpose of a selection statement in programming?
Tap to reveal answer
To execute code based on a condition. Allows programs to make decisions and branch execution paths.
To execute code based on a condition. Allows programs to make decisions and branch execution paths.
← Didn't Know|Knew It →
Identify the keyword used for creating a loop in Java.
Identify the keyword used for creating a loop in Java.
Tap to reveal answer
for, while, or do-while. These are the three main loop keywords in Java.
for, while, or do-while. These are the three main loop keywords in Java.
← Didn't Know|Knew It →
What does an if-else statement do?
What does an if-else statement do?
Tap to reveal answer
Executes code blocks based on condition being true or false. Provides branching logic for conditional execution.
Executes code blocks based on condition being true or false. Provides branching logic for conditional execution.
← Didn't Know|Knew It →
What is the syntax for a basic if statement in Java?
What is the syntax for a basic if statement in Java?
Tap to reveal answer
if (condition) { statements }. Standard conditional statement structure in Java.
if (condition) { statements }. Standard conditional statement structure in Java.
← Didn't Know|Knew It →
What is the purpose of a loop control variable?
What is the purpose of a loop control variable?
Tap to reveal answer
To control the number of iterations of the loop. Manages how many times the loop body executes.
To control the number of iterations of the loop. Manages how many times the loop body executes.
← Didn't Know|Knew It →
How is a for loop typically structured in Java?
How is a for loop typically structured in Java?
Tap to reveal answer
for (initialization; condition; update) { statements }. Three parts control initialization, termination, and increment.
for (initialization; condition; update) { statements }. Three parts control initialization, termination, and increment.
← Didn't Know|Knew It →
Identify the operator used to compare equality in Java.
Identify the operator used to compare equality in Java.
Tap to reveal answer
==. Double equals compares values, single equals assigns.
==. Double equals compares values, single equals assigns.
← Didn't Know|Knew It →
Find the error: for (int i = 0; i < 10; i--)
Find the error: for (int i = 0; i < 10; i--)
Tap to reveal answer
i-- should be i++. Decrement creates infinite loop since i never reaches 10.
i-- should be i++. Decrement creates infinite loop since i never reaches 10.
← Didn't Know|Knew It →
What keyword is used to exit a loop prematurely?
What keyword is used to exit a loop prematurely?
Tap to reveal answer
break. Immediately terminates loop execution.
break. Immediately terminates loop execution.
← Didn't Know|Knew It →
What does the continue statement do in a loop?
What does the continue statement do in a loop?
Tap to reveal answer
Skips the current iteration and continues with the next. Jumps to next iteration without executing remaining code.
Skips the current iteration and continues with the next. Jumps to next iteration without executing remaining code.
← Didn't Know|Knew It →
Identify the error: if (x = 5) { ... }
Identify the error: if (x = 5) { ... }
Tap to reveal answer
Use == instead of =. Single equals is assignment, not comparison.
Use == instead of =. Single equals is assignment, not comparison.
← Didn't Know|Knew It →
What is the output of: if (true) { System.out.print("A"); } else { System.out.print("B"); }
What is the output of: if (true) { System.out.print("A"); } else { System.out.print("B"); }
Tap to reveal answer
A. True condition executes the if block.
A. True condition executes the if block.
← Didn't Know|Knew It →
What is the output of: if (false) { System.out.print("X"); }
What is the output of: if (false) { System.out.print("X"); }
Tap to reveal answer
No output. False condition means if block doesn't execute.
No output. False condition means if block doesn't execute.
← Didn't Know|Knew It →
What happens if break is omitted in a switch case?
What happens if break is omitted in a switch case?
Tap to reveal answer
Fall-through to next case occurs. Code continues executing into subsequent cases.
Fall-through to next case occurs. Code continues executing into subsequent cases.
← 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.
A single execution of the loop body. One complete pass through the loop body.
← Didn't Know|Knew It →
How many times will this loop execute? for (int i = 0; i < 5; i++)
How many times will this loop execute? for (int i = 0; i < 5; i++)
Tap to reveal answer
5 times. Loop runs while i < 5: values 0, 1, 2, 3, 4.
5 times. Loop runs while i < 5: values 0, 1, 2, 3, 4.
← Didn't Know|Knew It →
What is the syntax for a do-while loop in Java?
What is the syntax for a do-while loop in Java?
Tap to reveal answer
do { statements } while (condition);. Body executes first, then condition is checked.
do { statements } while (condition);. Body executes first, then condition is checked.
← Didn't Know|Knew It →
What is the significance of the loop condition?
What is the significance of the loop condition?
Tap to reveal answer
Determines when the loop stops. Controls whether loop continues or terminates.
Determines when the loop stops. Controls whether loop continues or terminates.
← Didn't Know|Knew It →
Identify the error: for (int i = 0; i < 5; i++) { System.out.print(i); }
Identify the error: for (int i = 0; i < 5; i++) { System.out.print(i); }
Tap to reveal answer
No error. Syntax is correct for standard for loop.
No error. Syntax is correct for standard for loop.
← Didn't Know|Knew It →
Determine the output: int x = 5; if (x < 5) { x--; } System.out.print(x);
Determine the output: int x = 5; if (x < 5) { x--; } System.out.print(x);
Tap to reveal answer
- Condition is false, so x remains unchanged.
- Condition is false, so x remains unchanged.
← Didn't Know|Knew It →