FOR LOOP IN C

Maha

For Loop In C

  • The for loop in C language  is a control flow statement that allows you to execute a block of code repeatedly for a fixed number of times.
  • In a for loop  is used to iterate the statements or a part of the program several times. It is frequently used to traverse in the data structures like the array and linked list.

Syntax:

for(Expression 1; Expression 2; Expression 3)
{  
//code to be executed  
}

Program: 1

#include <stdio.h>
int main()
{
int i;
// for loop to print first 10 even numbers
for (i = 2; i <= 20; i += 2)
{
printf("%d ", i);
}
return 0;
}

Output:

2 4 6 8 10 12 14 16 18 20


Program: 2

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

Output:

1
2
3
4
5
6
7
8
9
10
Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send