Practical Coding in Java

Learn to write and validate your own code

Darren Kessner, PhD

(revised January 9, 2026)

Previous: Coding Exercises: Strings and Math

3. Loops and Algorithms

In this chapter we demonstrate the different types of loops in Java:

We also start exploring simple algorithms. An algorithm is a set of rules for performing a computation, like a recipe. You are implementing an algorithm when you write code to define a function. If an algorithm performs an action repeatedly, it is natural to use a loop to implement the algorithm.

In the examples and exercises, we explore some functions that use a loop to perform a computation.


Next: