The For loop in C

Rate this post

For loop is probably the most popular looping instruction.

The for allows us to specify three things about a loop in a single line:

  • Setting a loop counter to an initial value.
  • Testing the loop counter to determine whether its value has reached the number of repetitions desired.
  • Increasing the value of loop counter each time the program segment within the loop has been executed.

In General the for loop syntax is :

for (initialize counter; test counter ; increment counter )


perform the task;


Related Posts

  • 70
    Uses of Odd Loop In real life programming one comes across a situation when it is not known beforehand how many times the statements in the loop are to be executed. This situation can be programmed as shown below: /* Execution of a loop an unknown number of times */…
    Tags: loop, learn, programming
  • 60
    The keyword continue allows us to take up the control to the beginning of the loop, bypassing the statements inside the loop, which have not yet been executed. When continue is encountered inside any loop, control automatically passes to the beginning of the loop. A continue is usually associated with an…
    Tags: loop, learn, programming
  • 58
    It is often the case in programming that you want to do something a fixed number of times. Perhaps you want to calculate gross salaries of ten different persons, or you want to convert temperatures from centigrade to Fahrenheit for 15 different cities. Let us look at a example which…
    Tags: loop, programming, learn
  • 56
    Tags: programming, learn
  • 53
    The way if statements can be nested, similarly whiles and for can also be nested. To understand how nested loops work, look at the program given below: /* Example of nested loops */ main( ) { int r, c, sum ; for ( r = 1 ; r <= 3 ;…
    Tags: loop, learn, programming

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: