for-loop statement in C Programming

Share

for-statement


SYNTAX:

for (initialization expressionloop repetition conditionupdate 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.

About Dhiraj 40 Articles
Blogger on development, securities, and efficiency on web technologies.

Be the first to comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.