2. Introduction to loops
•
You may encounter situations, when a block of code
needs to be executed several number of times. In
general, statements are executed sequentially: The first
statement in a function is executed first, followed by
the second, and so on.
• Programming languages provide various control
structures that allow for more complicated execution
paths.
• A loop statement allows us to execute a statement or
group of statements multiple times.
4. About for loop
• for loop is used to execute a set of statements
repeatedly until a particular condition is satisfied. we
can say it an open ended loop.
• In for loop we have exactly two semicolons, one after
initialization and second after condition. In this loop
we can have more than one initialization or
increment/decrement, separated using comma
operator. for loop can have only one condition.
6. For example
• Write a program to print first 10 natural numbers
#include<stdio.h>
#include<conio.h>
void main( )
{
int x;
for(x=1; x<=10; x++)
{
printf("%dt",x);
}
getch();
}