Repetition in Java

by Ben Davidson

Objectives

Purpose of Repetition

Sometimes it is necessary to repeat a block of code many times.  It may seem like a simple solution to copy a block of code and paste it as many times as you need, but there is an alternative to this code-bloating idea.  In all programming languages there is some type of mechanism for repeating a block of code. This is known as repetition or looping.  Some examples of when you want to repeat a block of code are:

while Loops

do while Loops

for Loops

for each Loops

Nested Loops


Copyright © 2010, Maia L.L.C.  All rights reserved.