The while loop
Computers are good at carrying out very simple instructions at a very high speed. At the same time, many programs consist of executing a set of instructions repeatedly. Examples include reading a file, listing the contents of a directory, searching, aggregating, etc.
In this lesson, we will look at one of the ways to do things repeatedly in a program:
the while loop. At the end of the lesson, you will be able to:
- Write a simple
whileloop - Understand the various ways to terminate a loop
- Use
breakandcontinueto alter the flow of a loop - Use the accumulator pattern