for-loop statement in C Programming




for (initialization expressionloop repetition conditionupdate expression)




/* Display N asterisks. */
for (count_star = 0; count_star < N;count_star += 1)

printf(“* “);



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.

Would You Mind Sharing?


Be the first to comment

Leave a Reply

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