R
rami
please everybody ,can anyone tell me how to do an infinite loop in C
rami said:please everybody ,can anyone tell me how to do an infinite loop in C
please everybody ,can anyone tell me how to do an infinite loop in C
rami said:please everybody ,can anyone tell me how to do an infinite loop in C
pemo said:I have seen the
while(1)
construct produce warnings with some compilers - 'constant in conditional
expression' or some such thing.
The proper C way is I believe to use
for( ; ; )
that should *not* produce any complaints.
rami said:please everybody ,can anyone tell me how to do an infinite loop in C
Vladimir said:IMHO, this is a matter of taste (I prefer `while (1)`). They're both
correct.
I see no reason for either to produce diagnostic messages, although I
could think of a weak rationale for the one you were seeing.
pemo said:I must admit that I haven't seen this warning for quite a while now, but,
I can see why a compiler might see some merit in it, e.g., while(x = 1)
might produce the same output - and, of course, be rather useful.
John said:Pick any of the following:
1. for(;{...}
2. while(1) {...}
3. do {...} while(1);
Nick said:well the obvious way that applies to pretty well any programming
language
(I'm sure some will take it as a challange to give a counter example
(*)
is to use a while statement.
while (expression)
statement;
rami said:please everybody ,can anyone tell me how to do an infinite loop in C
John said:Pick any of the following:
1. for(;{...}
2. while(1) {...}
3. do {...} while(1);
I personally use 1.
August said:Well, some languages, as Oberon, have a special loop statement for
infinite loops and exit-in-the-middle loops:
LOOP
...
IF someCondition THEN EXIT END;
...
END
That way you can clearly express your intention with the loop. Moreover,
in Oberon local exits (break) are only allowed in LOOP statements.
Lew said:add to that list
4. label: ... goto label;
Nick said:I'm not sure I'd describe that as the "obvious" way to program an
infinite
loop. But then I've never programmed in Oberon.
please everybody ,can anyone tell me how to do an infinite loop in C
Our "shop standard" follows Stroustroup and uses for(;, pronounced
"forever."
Charles said: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.
Richard Heathfield said:rami said:
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.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.