Skip to main content

examples of for loop

/*
/// For loop
A for loop is a repetition control structure which allows us to 
write a loop that is executed a specific number of times.
 The loop enables us to perform n number of steps together in one line.
Syntax:

for (initialization expression; test expression; update expression)
{    
     // body of the loop
     // statements we want to execute
}

In for loop, a loop variable is used to control the loop.
 First initialize this loop variable to some value,
  then check whether this variable is less than or 
  greater than counter value. If statement is true, 
  then loop body is executed and loop variable gets updated . 
  Steps are repeated till exit condition comes.

1.Initialization Expression: In this expression we have to
 initialize the loop counter to some value. for example: int i=1;

2.Test Expression: In this expression we have to test the condition. 
If the condition evaluates to true then we will execute the body of 
loop and go to update expression otherwise we will exit from the for loop. 
For example: i <= 10;

3.Update Expression: After executing loop body this expression 
increments/decrements the loop variable by some value. for example: i++;
*/

#include<stdio.h>
int main()
{
    int i=0;
    for ( i = 0i <=10i++)
    {
        printf("hello world\n");
    }
    
    return 0;
}

Comments

Popular posts from this blog

example of typecasting in c

/*Type Casting in C Typecasting allows us to convert one data type into other. */ //simple example to cast int value into the float. #include <stdio.h>    int   main (){   float   f = ( float ) 9 / 4 ;     printf ( "f : %f \n " ,  f  );     return   0 ;   }