C uses two types of loops they are for and while. The for-loop has four distinct sections
Initialization
- Condition,
- Iteration
- Body
The first three sections follow the for keyword and are enclosed in parentheses. The sections must be divided by semi-colons, even when one or more of the sections are empty. The body of the loop follows and is enclosed in braces - except when there is only one statement in the body, when the braces are optional.
FOR loop:
* Before the first iteration of the loop,
* After each iteration of the loop,
Syntax -
for ( [initialization] ; [condition] ; [increment] )
{
Statement;
}
Example -
#include
int main()
{
int count;
printf("nYou have until the count of ten...");
for(count=0; count <10;>
printf("%dn",count);
printf("Time is up!");
return(0);
}
No comments:
Post a Comment