I have seen code (in C) which contains something similar to:
for(;;){
}
How would this work, and why is it used in any instance?
You use for example to introduce and emphasize something which shows that something is true.
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.
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.
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.)
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.
is an infinite loop something like
while(true)
{}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With