Comprehensive notes for Chapter 12 Loop Constructs. Covers while, do-while, for loops, nested loops, break, continue, and goto statements.
Definition: A statement or set of statements executed repeatedly is known as a loop. Also called iterative or repetitive structure.
Definition: Simplest loop. Executes executed one or more statements while the given condition remains true. Useful when iterations are unknown.
Syntax: while (condition) { statement(s); }
Condition is checked before execution. If false initially, loop never executes.
Definition: Executes statements while a condition is true, but checks the condition after the body.
Syntax: do { statement(s); } while (condition);
Key Feature: Guaranteed to execute at least once, even if the condition is false initially.
Definition: Most flexible loop, normally used when iterations are known (Counter-Controlled).
Syntax: for (initialization; condition; increment/decrement) { statement(s); }
Definition: A loop inside another loop. The inner loop completes all its iterations for each single iteration of the outer loop.
Example: Clock logic (inner loop for seconds, outer loop for minutes).