C Programing Loops (for loop)

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:

is executed repeatedly UNTIL the value of is FALSE.

* Before the first iteration of the loop, initializes variables for the loop.

* After each iteration of the loop, increments a loop counter. (Consequently, j++ is functionally the same as ++j.)

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: