In this unit you will learn: -
how to express repeated execution of statements
using a while loop -
how to use a while loop to compute a sum -
how to use a while loop to manipulate cells in
a Board object One of the features that make computers so
powerful is their ability to manipulate a large amount of data very
quickly. For many problems, this
requires the computer to perform an operation or a set of operations several
times, a concept that we refer to as repeated execution. If we’re going to have a separate Java
statement for each operation, our Java code will grow unmanageably large, not
to mention how dull and tedious of a task programming will be. This is why programming languages such as
Java include constructs that allow us to control how many times a set of
statements executes. Such constructs
are called loops (for obvious reasons), and Java has a handful types of loops
defined in it. The first one we’ll
look at is the while loop. |