LEARN, PRACTICE & EXCEL!
Why is repetition used in programming? Answer: To automate repeated tasks and avoid
redundant code.
What are Java's three looping structures? Answer: while, do-while, for.
What is the syntax of a while loop? Answer: while (condition) { body }
What does while loop do? Answer: Repeats body while condition is true.
What happens if while condition is false initially? Answer: The loop body never executes.
What is a counter-controlled loop? Answer: Runs a fixed number of times controlled by a
counter variable.
Example of counter-controlled loop? Answer: for (int i=0; i<10; i++) { ... }
What is a sentinel-controlled loop? Answer: Repeats until a special sentinel value is
encountered.
What is a sentinel value? Answer: A unique value that signals the end of input (e.g., -1).
What is an infinite loop? Answer: A loop that never terminates due to incorrect condition logic.
Example of infinite loop? Answer: while (true) { ... }
What is the syntax of do-while? Answer: do { body } while (condition);
How does do-while differ from while? Answer: do-while executes body at least once.
What happens if do-while condition is false initially? Answer: Body executes once, then loop
ends.
What is the syntax of a for loop? Answer: for (init; condition; update) { body }
What does initialization do in for? Answer: Executes once before loop starts.
What does condition do in for? Answer: Checked before each iteration; if false, loop ends.
What does update do in for? Answer: Executes after each iteration to update counter.
What is a nested loop? Answer: A loop inside another loop.
Common use of nested loops? Answer: Processing 2D arrays, tables, or patterns.
What is the scope of for loop variable? Answer: Local to the for loop unless declared outside.
APPHIA – Crafted with Care and Precision for Academic Excellence.
1