For loop repeat continuously for a specific number of times. We use for loop when we know how many times a loop must executed.
Syntax of for loop
for(Intialization; testExpression; increment)
{
//block of code;
}
Initialization in for loop is evaluated before the loop begins. TestExpression will check whether the condition evaluate to TRUE (nonzero) or FALSE (zero). In case it is TRUE, the body of the loop repeats. when testexpression false loop stops.
Example of for loop
# include<iostream.h>
# include<conio.h>
void main(){
int value= 5;
for(int i = 0; i < value ;i++)
{
cout<<i;
}
}
Output-
0
1
2
3
4
No comments:
Post a Comment