Velocity Reviews > how to do an infinite loop

how to do an infinite loop

James Watt
Guest
Posts: n/a

 11-15-2007
can anyone tell me how to do an infinite loop in C/C++, please ?

this is not a homework question .

Pietro Cerutti
Guest
Posts: n/a

 11-15-2007
James Watt wrote:
> can anyone tell me how to do an infinite loop in C/C++, please ?
>
> this is not a homework question .
>
>

int main(void) {
while(1);
return (0);
}

--
Pietro Cerutti

PGP Public Key:
http://gahr.ch/pgp

Default User
Guest
Posts: n/a

 11-15-2007
James Watt wrote:

> can anyone tell me how to do an infinite loop in C/C++, please ?
>
> this is not a homework question .

Do you understand what an infinite loop is?

Do you understand the various loop constructs?

If not, get a book and read. If you do, then apply the two and you'll
see how to do so.

Or you could go to Google and type in: infinite loop c

Brian

Jim Langston
Guest
Posts: n/a

 11-15-2007
"James Watt" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> can anyone tell me how to do an infinite loop in C/C++, please ?
>
> this is not a homework question .

for ( ;; )
/**/;

while (true)
/**/;

do
{ /**/ }
while ( true );

Martin Ambuhl
Guest
Posts: n/a

 11-16-2007
James Watt wrote:
> can anyone tell me how to do an infinite loop in C/C++, please ?

There being no such language as C/C++, it is impossible to do anything
with it.
In either C or C++, a simple statement like
while(1) ;
produces an infinite loop.

> this is not a homework question .

Certainly not; no teacher would be braindead enough to assign it.

jameskuyper@verizon.net
Guest
Posts: n/a

 11-16-2007
James Watt wrote:
> can anyone tell me how to do an infinite loop in C/C++, please ?

A better question is "why do an infinite loop?". Loops that are
deliberately written to be infinite are rare; ones where it was a good
idea are even rarer. Why do you want to do this?

Pietro Cerutti
Guest
Posts: n/a

 11-16-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> James Watt wrote:
>> can anyone tell me how to do an infinite loop in C/C++, please ?

>
> A better question is "why do an infinite loop?". Loops that are
> deliberately written to be infinite are rare; ones where it was a good
> idea are even rarer. Why do you want to do this?

Main loop in event-driven approach?

It would probably have some break statement to exit the loop when some
particular event happens, but it would still be an infinite loop

--
Pietro Cerutti

PGP Public Key:
http://gahr.ch/pgp

jameskuyper@verizon.net
Guest
Posts: n/a

 11-16-2007
Pietro Cerutti wrote:
> (E-Mail Removed) wrote:
> > James Watt wrote:
> >> can anyone tell me how to do an infinite loop in C/C++, please ?

> >
> > A better question is "why do an infinite loop?". Loops that are
> > deliberately written to be infinite are rare; ones where it was a good
> > idea are even rarer. Why do you want to do this?

>
> Main loop in event-driven approach?
>
> It would probably have some break statement to exit the loop when some
> particular event happens, but it would still be an infinite loop

A loop that ever actually exits should not be written as if it were an
infinite loop. It's misleading and confusing. The main way of leaving
a loop should always involve the constructs that make it a loop.

Gene
Guest
Posts: n/a

 11-16-2007
On Nov 15, 7:40 pm, (E-Mail Removed) wrote:
> Pietro Cerutti wrote:
>
> A loop that ever actually exits should not be written as if it were an
> infinite loop. It's misleading and confusing. The main way of leaving
> a loop should always involve the constructs that make it a loop.

I disagree with this if you mean that a loop should always exit at the

for (; {
if ( <exit condition> ) break;
}

is very often clearer than a loop that uses some contrived boolean
flag and sentinel conditionals just so that it can exit at the header
or trailer. To wit, Ada, which is designed expressly code for clarity
and simplicity, has the construct

loop
exit when <condition> ;
end loop;

Pietro Cerutti
Guest
Posts: n/a

 11-16-2007
(E-Mail Removed) wrote:
> Pietro Cerutti wrote:
>> (E-Mail Removed) wrote:
>>> James Watt wrote:
>>>> can anyone tell me how to do an infinite loop in C/C++, please ?
>>> A better question is "why do an infinite loop?". Loops that are
>>> deliberately written to be infinite are rare; ones where it was a good
>>> idea are even rarer. Why do you want to do this?

>> Main loop in event-driven approach?
>>
>> It would probably have some break statement to exit the loop when some
>> particular event happens, but it would still be an infinite loop

>
> A loop that ever actually exits should not be written as if it were an
> infinite loop. It's misleading and confusing. The main way of leaving
> a loop should always involve the constructs that make it a loop.

Well, it's a debate that resembles the one about the use of goto
statements. I wouldn't say that they shouldn't be used, no matter what.

Both goto statements and infinite loops, when typed in with the fingers
connected to the brain, in some cases could lead to better code quality
(read: clarity) than any other construct providing the same functionality.

--
Pietro Cerutti

PGP Public Key:
http://gahr.ch/pgp