Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is for(;;) used?

Tags:

c

for-loop

I have seen code (in C) which contains something similar to:

for(;;){
}

How would this work, and why is it used in any instance?

like image 455
user2976089 Avatar asked Dec 04 '13 22:12

user2976089


People also ask

Why is for example used?

You use for example to introduce and emphasize something which shows that something is true.

Why for is used in preposition?

It can serve as another means of disclosing distance, quantity, or a duration of time (e.g., “for several miles,” “for five dollars,” or “for ten minutes”). One of the most common uses of “for” is simply to identify the object in a sentence.

What means of for?

preposition. with the object or purpose of: to run for exercise. intended to belong to, or be used in connection with: equipment for the army;a closet for dishes. suiting the purposes or needs of: medicine for the aged. in order to obtain, gain, or acquire: a suit for alimony;to work for wages.

Which verb is used with for?

We use for + the -ing form of a verb to refer to the reason for something: You should talk to Jane about it. You know, she's famous for being a good listener. (A lot of people know she's such a good listener.)


2 Answers

It is the idiomatic way to have an infinite loop.

In the C Programming Language book, by Kernighan & Ritchie book it was introduced in section 3.5:

for (;;) {
    ...
 }

is an infinite loop, presumably to be broken by other means, such as a break or return.

like image 145
ouah Avatar answered Oct 26 '22 15:10

ouah


is an infinite loop something like

while(true) 
{}
like image 41
BRAHIM Kamel Avatar answered Oct 26 '22 15:10

BRAHIM Kamel