for loop in C

The for loop in C language is used to iterate the statements or a part of the program several times. It is frequently used to traverse the data structures like the array and linked list.

Syntax of for loop in C

The syntax of for loop in c language is given below:

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

Flowchart of for loop in C

for loop in c language flowchart

C for loop Examples

Let's see the simple program of for loop that prints table of 1.

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

Output

1
2
3
4
5
6
7
8
9
10

C Program: Print table for the given number using C for loop

  1. #include<stdio.h>  
  2. int main(){  
  3. int i=1,number=0;      
  4. printf("Enter a number: ");    
  5. scanf("%d",&number);    
  6. for(i=1;i<=10;i++){      
  7. printf("%d \n",(number*i));    
  8. }    
  9. return 0;  
  10. }    

Output

Enter a number: 2
2
4
6
8
10
12
14
16
18
20
Enter a number: 1000
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000