Working with Loops in Java
Candidate Teaching Demonstration
Northwood Technical College
Agenda
• 1. Types of Loops in Java
• 2. Loop Syntax & Structure
• 3. Common Mistakes & Debugging
• 4. Practice Activity
• 5. Assessment Method
Types of Loops in Java
• • for loop – when the number of iterations is
known
• • while loop – entry-controlled loop
• • do-while loop – exit-controlled loop
• • enhanced for loop – used for
arrays/collections
Loop Syntax Examples
• for (int i = 0; i < 5; i++) { ... }
• while (condition) { ... }
• do { ... } while (condition);
• for (int num : array) { ... }
Common Mistakes in Loops
• • Infinite loops (missing increment or wrong
condition)
• • Off-by-one errors (e.g., i <= [Link])
• • Misplaced semicolon (for (int i = 0; i < 5; i+
+);)
• • Modifying collection during iteration
Practice Activity
• • Identify the errors in the given loop
• Example:
• int i = 0;
• while (i < 5) {
• [Link](i);
• // missing increment => infinite loop
Assessment Method
• • Quick 3-question quiz at the end of class
• • Live coding problem: use loop to sum array
• • Exit ticket: describe one loop type and use
case
Summary
• • Loops are fundamental for controlling flow
• • Choose the loop based on your use case
• • Always test for boundary conditions
• • Practice helps in mastering syntax and logic