The For loop in C

for-loop-steps
for-loop-steps

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

  • 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
  • 52
    Welcome to the C Knowledge Base and Tutorial   Introduction to C Programming Start Learning C Programming What is C? Why We should learn C C Character Set : Constants, Variables and Keywords Constant and Variable in C: C Keywords: Types of C Constant Rules for Constructing Integer Constants Rules…
    Tags: programming, learn
  • 47
    The programs that we have learned/developed in this tutorial so far used either a sequential or a decision control instruction. In the first one, the calculations were carried out in a fixed order, while in the second, an appropriate set of instructions were executed depending upon the outcome of the condition…
    Tags: loop, programming, learn
  • 43
    The if statement can take any of the following forms: if ( condition ) do this ; if ( condition ) { do this ; and this ; } if ( condition ) do this ; else do this ; if ( condition ) { do this ; and this…
    Tags: learn, programming
  • 41
    Let's have an example to understand else if clause : /* else if ladder demo */ main( ) { int m1, m2, m3, m4, m5, per ; per = ( m1+ m2 + m3 + m4+ m5 ) / per ; if ( per >= 60 ) printf ( "First…
    Tags: learn, programming

Leave a Reply

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

%d bloggers like this: