When we want to execute a set of statements or a block of code repeatedly till a particular condition is true, we use LOOP. There exists 3 basic loops –
- For loop
- While loop
- do while loop

#include<stdio.h>
void main(){
int x;
for(x=1;x<10;x=x+1){
printf("value of x: %d\n",x);
}
}
To use for loop we need to start with a keyword for then in round bracket we mention initialization ; condition ; increment/decrement semicolon separated. the in the curly bracket we mention the set of statements or block of code that we need to execute repeatedly till the condition is true. we use increment/decrement to reach closer to the termination condition.
It all starts with initialization (x=1), then condition is checked (x<10) if true execute the for loop body. Lets say the condition was true and the for loop body got executed, then the control goes to increment(x++), the condition(x<10) is checked, if true execute the for loop body. This will continue till x=9, but when x is incremented as x=10, then the condition returns false and the control of program says ‘BYE’ to for loop and starts executing the rest of the code.