Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > how to do an infinite loop

Reply
Thread Tools

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 .


 
Reply With Quote
 
 
 
 
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
 
Reply With Quote
 
 
 
 
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

 
Reply With Quote
 
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 );


 
Reply With Quote
 
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.
 
Reply With Quote
 
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?
 
Reply With Quote
 
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
 
Reply With Quote
 
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.
 
Reply With Quote
 
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
loop head or tail.

for (; {
... // yada yada
if ( <exit condition> ) break;
... // more yada yada
}

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
... -- yada yada
exit when <condition> ;
... -- more yada yada
end loop;
 
Reply With Quote
 
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
infinite loop unexpectly dies Vedran Vukotic Perl 0 03-02-2006 07:43 AM
loop thru a STL list causes an infinite loop Allerdyce.John@gmail.com C++ 5 01-31-2006 03:21 PM
Infinite loop when using Server.Transfer Alexander Bosch ASP .Net 11 11-10-2004 08:53 AM



Advertisments