C – For Loop

for loop: Execute a block of instructions repeatedly as long as the condition is valid. We use for loop only when we know the number of iterations to do.

Syntax:

for(init ; condition ; modify)
{
            statements;
}
 
for(start ; stop ; step)
{
            statements;
}

FlowChart:

C Program to Print 1 to 10 Numbers:

int main()
{
            int i;
            for(i=1 ; i<=10 ; i++){
                        printf(“%d \n”, i);
            }          
            return 0;
}

C Program to Print Numbers from 10 to 1:

int main()
{
            int i;
            for(i=10 ; i>=1 ; i–){
                        printf(“%d \n”, i);
            }
            return 0;
}

C Program to Print 1 to N:

int main()
{
            int n, i;
            printf(“Enter n value : “);
            scanf(“%d”, &n);
            for(i=1 ; i<=n ; i++){
                        printf(“%d \n”, i);
            }          
            return 0;
}

C Program to display A to Z

#include<stdio.h>
int main()
{
            char ch;
            for(ch=’A’ ; ch<=’Z’ ; ch++){
                        printf(“%c”, ch);
            }          
            return 0;
}

C Program to display ASCII values from A to Z

#include<stdio.h>
int main()
{
            char ch;
            for(ch=’A’ ; ch<=’Z’ ; ch++){
                        printf(“%c : %d \n”, ch, ch);
            }          
            return 0;
}

C Program to display ASCII character set

#include<stdio.h>
int main()
{
            int x;
            for(x=0 ; x<256 ; x++){
                        printf(“%d : %c \n”, x, x);
            }          
            return 0;
}
Scroll to Top