Professional Documents
Culture Documents
Control Structures - For Statement
Control Structures - For Statement
__________________________________________________________________
CONTROL STRUCTURES – FOR STATEMENT
___________________________________
OBJECTIVES:
OVERVIEW
Looping statements are statements in Turbo C that allows certain operation to be repeated several
times. An example of this is the while statement.
FOR STATEMENT
This looping statement is capable of performing iteration using the parameters on its
general form unlike while statement that has separate declarations of its other iteration
parameters.
Syntax
Sample Declaration
for (x=1;x<=5;x++)
Sample Program
Sample Output
Sample Program
#include<stdio.h>
/* This program can determine the sum of 5 input integers*/
main()
{
int i, sum, n;
for(i=0;i<5;i++)
{
printf(“Enter numbers: \n”);
scanf(“%d”, &n);
sum+=n;
}
printf(“Sum of 5 numbers is: %d”, n);
}
Sample Output
Enter numbers:
1
3
5
7
2
Sum of 5 numbers is: 18
SUMMARY
For statement is a statement that can perform iteration. It has three (3)
major components:
Initialization statement
Condition
Increment / decrement