Looping

Many programming problems are solved by repeatedly acting on the same data.

Iteration means doing the same thing again and again. The principal method of iteration is the loop.


The Roots of Looping goto

In the primitive days of early computer science, loops consisted of a label, some statements, and a jump.

In C++, a label is just a name followed by a colon (:). The label is placed to the left of a legal C++ statement, and a jump is accomplished by writing goto followed by the label name.

Why goto Isn't Used

goto is generally not used in C++, and for good reason. goto statements can cause a jump to any location in your source code, backward or forward. The indiscriminate use of goto statements has caused tangled, miserable, impossible-to-read programs known as spaghetti code.

To avoid the use of goto, more sophisticated, tightly controlled looping commands have been introduced: for, while, and do...while. Using these commands makes programs that are more easily understood, and goto is generally avoided.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.94.153