The for loop allows automatic initialization and incrementation of a counter variable. The general form is

 for(initialization; condition; increment) {      statement block }

If the statement block is only one statement, the braces are not necessary.

Although the for allows a number of variations, generally the initialization sets a loop control variable to its starting value. The condition is usually a relational statement that checks the loop control variable against a termination value, and increment increments (or decrements) it. If the condition is false to begin with, the body of the for loop will not execute even once.

The following statement will print the message “hello” ten times:

for(t=0; t<10; t++) cout << "hello\n";

C(s)C++ Programmer's Reference
C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539 © 2008-2017.
If you may any questions please contact us: