Repetition Structures
Learning Objectives
In addition to all previous competencies, upon completion of this unit, you should be able to:
- Understand and explain the different loop categories
- Understand and create commonly used loops
- Understand and create nested loops
- Validate end-user input
- Understand how to avoid infinite loops
- Understand and create loops with decision structures
Unit Learning Activities
In this unit you will learn the basics of repetition structures. After all, computers are very good at repeating a sequence of commands over and over without tiring. Repetition structures should be firmly implanted into your bag of tricks. Please note, this unit includes a detailed example which I highly recommend you type into a NetBeans project, make sure it works, and step through the code.
Each link below takes you to a specific chapter within this unit. Please take the time to review all the chapters and when available, complete the interactive activities.
"Success is the sum of small efforts - repeated day in and day out." - Robert Collier
- Repetition Structures Overview
- Pre-test Loops
- Post-test Loops
- Counter-Controlled Loops
- Condition-Controlled Loops
- Infinite Loops
- What You Learned
- Counter-Controlled Loops
- Counter-Controlled
whileLoop - Counter-Controlled
forLoop - What You Learned
- Counter-Controlled
- Condition-Controlled Loops
- Stop on a Sentinel
- Using Two Sentinels
- Things to Remember
- Combining Repetition Structures and Decision Structures
- Testing for
true - Code Example
- Repetition Structure with Nested Decision
- Things to Remember
- Input Validation
- Detailed Example
- Testing for
- Nested Loops
- Code Example
- The Concept
- Interactive Live Demo
- This unit includes the following detailed example
- Check for Even Number by combining repetition and decision structures