473,889 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to do an infinite loop

please everybody ,can anyone tell me how to do an infinite loop in C

Mar 1 '06
59 79847
Ico said:
Richard Heathfield <in*****@invali d.invalid> wrote:
rami said:
please everybody ,can anyone tell me how to do an infinite loop in C


I have written a program for you, that contains an infinite loop, but it
wouldn't be right to show you the code until its test run is complete.


Done yet ?


Still going strong.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Mar 2 '06 #21
Pedro Graca wrote:
Lew Pitcher wrote:

John Bode wrote:
rami wrote:
please everybody ,can anyone tell me how to do an infinite loop in C

Pick any of the following:

1. for(;;) {...}
2. while(1) {...}
3. do {...} while(1);


add to that list
4. label: ... goto label;


Do not add to the list (unless you're considering an "infinite" computer)
void f(void) { ...; f(); }


inline void f(void) { ...;f(); } ???

or a compiler who knows what means "tail recursion".

Mar 2 '06 #22
On 2006-03-02, CBFalconer <cb********@yah oo.com> wrote:
Charles Krug wrote:
On 2006-03-01, rami <do******@yahoo .com> wrote:
please everybody ,can anyone tell me how to do an infinite loop
in C


Our "shop standard" follows Stroustroup and uses for(;;),
pronounced "forever."

Several shops ago, I used while(17) until my boss complained he
couldn't understand it.


#define until while
#define the_cows_come_h ome 17

do {
... stuff ...
} until (the_cows_come_ home);

some alternatives (mix and match)

#define hell_freezes_ov er (1 != 0)
#define no_dog_has_flea s (EOF < 0)


Heh. It makes more sense to define them as false statements and define
until(x) as while(!(x)) - since that is the semantics of until in
languages that actually have it.
Mar 2 '06 #23

"CBFalconer " wrote:
Charles Krug wrote:
On 2006-03-01, rami <do******@yahoo .com> wrote:
please everybody ,can anyone tell me how to do an infinite loop
in C


Our "shop standard" follows Stroustroup and uses for(;;),
pronounced "forever."

Several shops ago, I used while(17) until my boss complained he
couldn't understand it.


#define until while
#define the_cows_come_h ome 17

do {
... stuff ...
} until (the_cows_come_ home);

some alternatives (mix and match)

#define hell_freezes_ov er (1 != 0)
#define no_dog_has_flea s (EOF < 0)


Extraordinarily great idea!!! Had a good laugh...

how about:

#define you_are_old_and _grey (0?(0?0:0):1)
#define you_stop_wonder ing_about_that_ constant 1

:-)

John
Mar 2 '06 #24
"John F" <sp**@127.0.0.1 > wrote in message
news:44******** *************** @tunews.univie. ac.at...
Extraordinarily great idea!!! Had a good laugh...

how about:

#define you_are_old_and _grey (0?(0?0:0):1)
#define you_stop_wonder ing_about_that_ constant 1


I put off mentioning this one, because I was SURE someone would beat me to it.
Maybe someone did and I didn't catch the message.

I've run across this a number of times:

#define ever ;;

for (ever)
{
/* We're in here forever */
}
Mar 2 '06 #25

"William J. Leary Jr." wrote:
"John F" <sp**@127.0.0.1 > wrote:
Extraordinarily great idea!!! Had a good laugh...

how about:

#define you_are_old_and _grey (0?(0?0:0):1)
#define you_stop_wonder ing_about_that_ constant 1


I put off mentioning this one, because I was SURE someone would beat me to
it.
Maybe someone did and I didn't catch the message.

I've run across this a number of times:

#define ever ;;

for (ever)
{
/* We're in here forever */
}


That's great! :-)

--
John
Mar 2 '06 #26
"William J. Leary Jr." <Bi********@msn .com> writes:
"John F" <sp**@127.0.0.1 > wrote in message
news:44******** *************** @tunews.univie. ac.at...
Extraordinarily great idea!!! Had a good laugh...

how about:

#define you_are_old_and _grey (0?(0?0:0):1)
#define you_stop_wonder ing_about_that_ constant 1


I put off mentioning this one, because I was SURE someone would beat
me to it. Maybe someone did and I didn't catch the message.

I've run across this a number of times:

#define ever ;;

for (ever)
{
/* We're in here forever */
}


I've used that myself, many years ago.

It's very clever. In this context, "clever" is a derogatory term.

I appreciate the humor of cleverly obfuscated code, but if you want an
infinite loop in C code that's intended to be maintained, there are
two common ways to do it:

while (1) { ... }
for (;;) { ... }

There is *no* good reason to use anything else.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 3 '06 #27
William J. Leary Jr. wrote:
#define ever ;;

for (ever)
{
/* We're in here forever */
}


Macros can be a great tool, but they should not be used, in my opinion,
as syntactic sugar. The base syntax of the language should not be
modified in any way if you want your code to be readable. A 'for'
loop without two visible ';' is a syntax mess. Don't do it.

Besides, I try to stick to the convention of declaring macros in all
uppercase. This way, you can see immediately if you are dealing with a
macro.

Preprocessors are handy but dangerous, as they are not really part
of the language itself. Thus you should avoid abstracting its use
at all costs.
Mar 3 '06 #28

"Guillaume" wrote:
William J. Leary Jr. wrote:
#define ever ;;

for (ever)
{
/* We're in here forever */
}
Macros can be a great tool, but they should not be used, in my opinion,
as syntactic sugar. The base syntax of the language should not be
modified in any way if you want your code to be readable. A 'for'
loop without two visible ';' is a syntax mess. Don't do it.


#define ever

for (;ever;)
{
/*code to do*/
}

better?
Besides, I try to stick to the convention of declaring macros in all
uppercase. This way, you can see immediately if you are dealing with a
macro.

Preprocessors are handy but dangerous, as they are not really part
of the language itself. Thus you should avoid abstracting its use
at all costs.


ACK ... It is great for general purpose use but should not be used to "bend"
the language...

--
regards
John
Mar 3 '06 #29
"John F" <sp**@127.0.0.1 > writes:
"Guillaume" wrote:
William J. Leary Jr. wrote:
#define ever ;;

for (ever)
{
/* We're in here forever */
}


Macros can be a great tool, but they should not be used, in my opinion,
as syntactic sugar. The base syntax of the language should not be
modified in any way if you want your code to be readable. A 'for'
loop without two visible ';' is a syntax mess. Don't do it.


#define ever

for (;ever;)
{
/*code to do*/
}

better?


No.

If someone reading your code knows C, he knows perfectly well what
"for (;;)" means; he'll have no idea what "ever" means without looking
it up. If he doesn't know C, no amount of preprocessor trickery will
let him understand the code; rather, it will prevent him from learning
good C.

(I don't think you meant to imply that it *is* better, so take this as
an expansion on what you wrote, not a criticism.)

Note that a sufficiently malicious programmer could do something like
this:

#define ever 0

for (;ever;) {
/* this is never executed */
}

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 3 '06 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
5620
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a fallacy built on the assumption of mythical infinite all powerfull machines. In reality we deal with finite machines that are capable of two states in a loop, they either terminate, or repeat themselves. In the mythical halting problem scenario...
5
4957
by: mailpitches | last post by:
Hello, Is there any way to kill a Javascript infinite loop in Safari without force-quitting the browser? MP
4
2644
by: LOPEZ GARCIA DE LOMANA, ADRIAN | last post by:
Hi all, I have a question with some code I'm writting: def main(): if option == 1: function_a()
10
7664
by: Steven Woody | last post by:
i have a program which always run dead after one or two days, i think somewhere a piece of the code is suspicious of involving into a infinite loop. but for some reason, it is very hard to debug. so i thing there might be tool which can statically analysis the code and notice me this kind of potential problems if found. any suggestion? ( i prefer linux open source tools ) thanks. -
44
4320
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
0
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9805
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10439
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9603
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7991
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7148
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6025
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4249
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.