for-statement
SYNTAX:
for (initialization expression; loop repetition condition; update expression)
{
statement;
}
EXAMPLE:
/* Display N asterisks. */
for (count_star = 0; count_star < N;count_star += 1)
{
printf(“* “);
}
INTERPRETATION:
First, the initialization expression is executed. Then, the loop repetition condition is tested. If it is true, the statement is executed, and the update expression is evaluated. Then the loop repetition condition is retested. The statement is repeated as long as the loop repetition condition is true. When this condition is tested and found to be false, the for loop is exited, and the next program statement after the for statement is executed.
Caution: Although C permits the use of fractional values for counting loop control variables of type double, we strongly discourage this practice. Counting loops with type double control variables will not always execute the same number of times on different computers.
Leave a Reply
You must be logged in to post a comment.