Computer Science, asked by svk7800, 1 year ago

unique features of for loop

Answers

Answered by sourishdgreat1
0
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&∑<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.


Answered by shebuchella
0

A for-loop has two parts: a header specifying the iteration, and a body which is executed once per iteration. ... For-loops are typically used when the number of iterations is known before entering the loop. For-loops can be thought of as shorthands for while-loops which increment and test a loop variable.

Similar questions