C++ tutorial: loops and branches


Loops and branches are key features of all programs
So far we have examined simple C/C++ programs where the statements are executed, one at a time and from top to bottom. In practice, it will usually be necessary for the 'flow' of execution in a program to be more complex than this. 'Branches' are points in the program where execution can go one way or another; 'loops' are parts of a program that are executed repeatedly.

C/C++ has a reasonably large selection of loop and brach instructions; in fact, there are more than we theoretically need. Often the choice of which type to use is a matter of personal preference or convention. On a first reading, you might prefer just to look at the sections for 'if', 'while' and 'for'. These three constructs will give enough flexibility for simple applications.

©1994-2003 Kevin Boone, all rights reserved