Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the term "empty loop" refer to exactly in C and C++?

Tags:

c++

c

Is it this kind of thing:

for(;;)  {    statements;  } 

Or is it this:

for(initialisation;condition;updation) { } 

I am looking for answers with references to a variety of sources.

like image 364
vidit jain Avatar asked Jan 04 '11 09:01

vidit jain


People also ask

What is empty loop in C?

An empty loop is a loop which has an empty body, e.g. for(int i = 0; i < 10; ++i) {} while(cin) {} (note that the second example here also happens to be endless)

What is empty loop example?

An empty loop is a loop which does not have any updation or value of iteration. For example, for(int i = 1;;) (in Java) An empty loop is infinite.

Is empty loop an infinite loop?

An empty loop is a loop that doesn't contain any executable statement, whereas, an infinite loop is a loop that runs an infinite number of times. An empty loop contain only one empty statement. They are mostly used to produce time breaks. for(int a=0;a<10;a++); An infinite loop on the other hand continues forever.

Which statement is used to empty loops?

We use pass statement to write empty loops. Pass is also used for empty control statement, function and classes.


2 Answers

Your first case (for with empty expressions) is an infinite loop and the second one (with empty body of the for statement) is an empty loop

like image 124
Bojan Komazec Avatar answered Sep 30 '22 23:09

Bojan Komazec


In my environment it is like this:

for(;;) { statements; } 

endless loop

for(initialisation;condition;updation) { }  

empty loop

like image 43
RoflcoptrException Avatar answered Sep 30 '22 22:09

RoflcoptrException