for-loop
For statement
For statement is used to execute a statement or a group of statement for a known number of times.
the general form
for(control-variable;condition;increment/decrement)
{
body of the loop
}
next statement;
If the value of the condition is true then the body of the loop will be executed, then the value of the control-variable will be incremented or decremented.when the conditionis false then the control is transferred to the next statement
For statement is used to execute a statement or a group of statement for a known number of times.
the general form
for(control-variable;condition;increment/decrement)
{
body of the loop
}
next statement;
If the value of the condition is true then the body of the loop will be executed, then the value of the control-variable will be incremented or decremented.when the conditionis false then the control is transferred to the next statement
Block diagram of for-loop
Example program
#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum=0;
clrscr();
for(i=1;i<=10;i++)
{
sum=sum+1;
}
printf("sum=%d",sum);
getch();
}
Switch statement
switch statement is an extension of if...else statement.This permits any number of branches.
the General fornm is
switch(expression)
{
case 1
statement block-1;
break;
Comments
Post a Comment