The C++Course provides a general introduction to programming in C++. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details. |
Home Vectors For Loops | ||
See also: The While Statement, Iteration | ||
For Loops
This type of loop is so common that there is an alternate loop statement, called for, that expresses it more concisely. The general syntax looks like this: for (INITIALIZER; CONDITION; INCREMENTOR) {BODY } This statement is exactly equivalent to INITIALIZER;while (CONDITION) { BODY INCREMENTOR } except that it is more concise and, since it puts all the loop-related statements in one place, it is easier to read. For example: for (int i = 0; i < 4; i++) {cout << count[i] << endl; } is equivalent to int i = 0;while (i < 4) { cout << count[i] << endl; i++; }
|
||
Home Vectors For Loops |