Write about Additional Features of For Loop?

The for loop in C has several capabilities that are not found in other loop constructs.

1.More than one variable can be initialized at a time in the for statement.
Ex:– for(p=1, n=0; n<10;++n )

2. The increment section may also have more than one part.
Ex:–for(n=1, m=50; n<=m;n=n+1, m =m–1)

The multiple arguments in initialization section & in the increment section are separated by commas.

3. The test–condition may have any compound relation & the testing need not be limited only to the loop control variable.
Ex:–for(i=1; i<10&&sum<100;i++)

4.It is also possible to use expressions in the assignment statements of initialization & increment sections.
Ex:– for(x=(m+n)/2; x>0;x=x/2)

5. Another unique aspect of for loop is that one or more sections can be omitted, if necessary.
Ex:–m=5;
For(;m!=100;)
{
printf(“%d\n”,m);
m=m+5;
}

6. We can set uptime delay loops using the null statement as follows.
Ex:– for (i=1000;j>0;j=j–1);

This loop is executed 1000 times without producing any output. It simply causes a time delay.

Related

C Language 4210599986940795611

Post a Comment

emo-but-icon

item