FOR LOOP

In C programming, a for loop is a control flow statement that allows you to repeatedly execute a block of code for a specific number of times. The general syntax of a for loop in C is as follows:

for (initialization; condition; update) {

    // code to be executed in each iteration

    // ...

}

Here's a breakdown of the components:

Initialization: This part is executed once before the loop starts. It is typically used to initialize a loop control variable.

 

Condition: This is a boolean expression that is evaluated before each iteration. If the condition is true, the loop continues; otherwise, it exits.

 

Update: This part is executed after each iteration and is often used to modify the loop control variable.

 

for(initialize ; check ; modify){

logic

 

#include<stdio.h>

void main()

{

  for(int i=0 ;i<=10 ;i++)

{

  printf(“%d”, i);

}

}

Output   12345678910

write a program to print the num b/w 10 – 1 using for loop

#include<stdio.h>

void main()

{

  for(int i=10 ;i>0 ;i--)

{

  printf(“%d”,i);

}

}

output   10987654321

Print the table of 2 using for loop

#include<stdio.h>

void main()

{

  int j=2;

  for(int i=1 ;i<=10 ;i++){

  printf(“%d”, j*i);

}

}

output 2468101214161820