blogger Indonesia

Follow judhyns blog

THE for LOOP

Introduction

The for loop is used only when the number of iterations is predetermined, for example, 10 iterations or 100 iterations.

Program/Example

The general format for the for loop is

    for  (initializing; continuation condition; update)     simple or compound statement     For example, for (i = 0; i < 5; i++) {     printf("value of i"); } 

Explanation

  1. The for loop has four components; three are given in parentheses and one in the loop body.

  2. All three components between the parentheses are optional.

  3. The initialization part is executed first and only once.

  4. The condition is evaluated before the loop body is executed. If the condition is false then the loop body is not executed.

  5. The update part is executed only after the loop body is executed and is generally used for updating the loop variables.

  6. The absence of a condition is taken as true.

  7. It is the responsibility of the programmer to make sure the condition is false after certain iterations.

No comments:

feed

PR Check

activesearchresults

judhyn's blog

 

http://www.judhyn.blogspot.com | |