Reading a key inside a loop

K

Keith Thompson

Richard Heathfield said:
Keith Thompson said:

I disagree. I for one consider both these forms to be aberrations rather
than idioms. The most common idiomatic ways to write a loop in C are
surely:

for(i = start; i < stop; i += inc)

and

while(conditional_expression)
[...]

Why yes, I did mean to write "infinite loop" rather than just "loop".
Kind of you to point out my error.
 
R

Richard Heathfield

Keith Thompson said:
Why yes, I did mean to write "infinite loop" rather than just "loop".
Kind of you to point out my error.

And in my own inimitable way, too. :)

(Yeah, okay, it was a bit harsh - sorry 'bout that.)
 
A

army1987

Army1987 wrote:

False.

for, while, and if are obvious examples.

You can replace for and while with recursive function calls and if
with the ternary operator. :)
 
O

Old Wolf

And maybe
#define NEVER ;0;

Some compilers have a bug where for(NEVER) would execute
the loop body once. That's what you get for writing such
silly code!
 
J

Joe Wright

Old said:
Some compilers have a bug where for(NEVER) would execute
the loop body once. That's what you get for writing such
silly code!
If you know a compiler that will execute..

for (;0;) puts("Nonsense");

...please tell us which. I want to avoid it.
 
O

Old Wolf

Joe said:
If you know a compiler that will execute..

for (;0;) puts("Nonsense");

..please tell us which. I want to avoid it.

Turbo C++ 2.0 will generate output for that. I'm not sure if this
was fixed for version 3.0.
 
S

santosh

Old said:
Turbo C++ 2.0 will generate output for that. I'm not sure if this
was fixed for version 3.0.

I think even a later version of Borland's C++ implementations had this
defect. It's fixed in my 5.5 version.
 
A

Army1987

Keith Thompson said:
And C with Lisp.

Have I already told you that one of the points in my list of things to do
before dying is writing a functional-paradigm program in a language that
everybody claims to be imperative?
 
A

Army1987

Old Wolf said:
Some compilers have a bug where for(NEVER) would execute
the loop body once. That's what you get for writing such
silly code!

My God...

Do they work correctly if the condition is nonconstant but happens to be
false at the beginning? What if I write for (i=0; i<n; i++) printf("%d\n",
i); when n is non-positive?
 
H

hstagni

Hum,,,,,Why are you talking about "how to make the perfect no-end-loop
". while(1==1), for(;;), while(1), while(666 > 0), etc etc etc, they
all work the same way, dont they?????????????

Anyway, my problem was solved using ncurses nodelay() function, like
Thomas Dickey said,,,,
THANKS,,,

"No delaying. Usually a call to getch() waits until a key is hit. If
you have called nodelay(stdscr, TRUE), then getch() will work in a non-
blocking manner -- it will return ERR if the key input is not ready.
This is usually useful for writing game-like programs, where the
promptness of user response matters. "
 
F

Flash Gordon

hstagni wrote, On 05/04/07 21:57:

Please provide some context when posting. There is no guarantee that we
can see the message you are replying to.
Hum,,,,,Why are you talking about "how to make the perfect no-end-loop
". while(1==1), for(;;), while(1), while(666 > 0), etc etc etc, they
all work the same way, dont they?????????????

<snip>

I would assume that people were discussing it because they wanted to.
Why do you think people should not discus what they want to?
 
H

hstagni

hstagni wrote, On 05/04/07 21:57:

Please provide some context when posting. There is no guarantee that we
can see the message you are replying to.


<snip>

I would assume that people were discussing it because they wanted to.
Why do you think people should not discus what they want to?

open a new thread and discuss about whatever you want :p
50 msg and only a couple even tried to solve my question
o_O
 
K

Keith Thompson

hstagni said:
open a new thread and discuss about whatever you want :p
50 msg and only a couple even tried to solve my question
o_O

And how many answers did you need? I believe you've already gotten
all the help on your question that it's possible for this newsgroup to
give you. If not, feel free to ask again, explaining why the previous
answers to your question were insufficient.

Quoting my own followup in this thread about a week ago (referring
to the FAQ, found at <http://www.c-faq.com>):

| Mark pointed you to question 19.1. Question 19.2 is actually more
| applicable to what you're trying to do. But the conclusion is the
| same: there's no way to do what you're trying to do in standard C, but
| there's likely to be a system-specific way to do it (which you'll have
| to ask about elsewhere).

The poster who starts a thread does not own the thread, and the rest
of us are not obligated to restrict our discussions to answering the
original question. Very often, followups raise new issues, and
interesting discussion ensues. As long as it remains topical for the
newsgroup, that's a good thing.

If we had gone off on a tangent *instead of* answering your question,
you might have a legitimate gripe.
 
T

Thomas Dickey

Keith Thompson said:
And how many answers did you need? I believe you've already gotten

not yours.
It was technically inept.
And this followup of yours is rude in any context.

But we've come to expect that from you.

regards.
 
K

Keith Thompson

Thomas Dickey said:
not yours.
It was technically inept.
And this followup of yours is rude in any context.

But we've come to expect that from you.

Would you care to explain that, or are you just a troll?
 
R

Richard Heathfield

Keith Thompson said:
Would you care to explain that, or are you just a troll?

If he's /the/ Thomas Dickey, he is certainly not *just* a troll, and is
unlikely even to be unjust a troll.

If he's just /a/ Thomas Dickey, all bets are off. :)
 
T

Thomas Dickey

Would you care to explain that, or are you just a troll?

time (and interest) permitting.

technically inept:
reviewing your non-FAQ postings to this thread,
all were variations on making an infinite for-loop.
None were responsive to OP's question.
Not even an insightful pointer to the FAQ...

rude:
Consider getting a response from one of your co-workers
(I assume you have some) to a simple question, which
reads like that paragraph beginning
And how many answers did you need?
Then consider what you'd do if it happened often.
 
K

Keith Thompson

Prompted by Richard Heathfield's parallel followup, I took a quick
look at your posting history. Based on that, I withdraw the "just a
troll" remark.
time (and interest) permitting.

technically inept:
reviewing your non-FAQ postings to this thread,
all were variations on making an infinite for-loop.
None were responsive to OP's question.

The topic drifted. It happens.

None of my non-FAQ postings were responsive to the OP's *original*
question, simply because the OP's original question was a FAQ.

(And I'll note in pssing that calling me inept and rude doesn't do
much to answer the OP's question either.)
Not even an insightful pointer to the FAQ...

I disagree. Here's one my my responses in this thread (I quoted part
of it just a few articles upthread; I'll quote more of it here):

| > OK,,,THANK YOU ALL
| > (I was trying to write while(1==1), cause for(;;) is kind of dirty to
| > me :p )
|
| "while (1)" and "for (;;)" are the most common idiomatic ways to write
| a loop in C. "while (1==1)" will just cause your readers to scratch
| their heads.
|
| [...]
|
| >>>>>> About the FAQ
| > This FAQ you sent me does not applie(?) to my question(sorry if im
| > wrong). Of course I will have to use something like ncurses getchar().
| > However, this function has the same 'problem' i mentioned before: it
| > WAITS for a key, stopping my tetris animation :(
|
| Mark pointed you to question 19.1. Question 19.2 is actually more
| applicable to what you're trying to do. But the conclusion is the
| same: there's no way to do what you're trying to do in standard C, but
| there's likely to be a system-specific way to do it (which you'll have
| to ask about elsewhere).
|
| And please learn to quote properly. The Google Groups interface does
| this for you. You may find the following links useful:
|
| http://cfaj.freeshell.org/google/
| http://www.caliburn.nl/topposting.html
| http://www.cpax.org.uk/prg/writings/topposting.php

That was basically three paragraphs. The first was about infinite
loops, and it was a direct response to something the OP asked (though
it wasn't the OP's original question). The second was a pointer to
the FAQ, which was a response to the OP's original question. Take a
look at question 19.2 in the FAQ.

Do you disagree that "See question 19.2 in the FAQ" is the best answer
to the OP's original question? If so, I'd appreciate an explanation.

And the third paragraph was merely intended to help the OP make
himself understood. He was prefixing quoted text with ">>>" and not
attributing it. Quoting and attributing correctly is actually easier,
even with Google Groups.
rude:
Consider getting a response from one of your co-workers
(I assume you have some) to a simple question, which
reads like that paragraph beginning
And how many answers did you need?
Then consider what you'd do if it happened often.

If it happened often because I was re-asking questions that had
already been answered, I would consider paying more attention in the
first place.

I don't believe I was either inept or rude. If you can convince me
that I'm mistaken on either point, I'll have learned something.
 
T

Thomas Dickey

Keith Thompson said:
Do you disagree that "See question 19.2 in the FAQ" is the best answer
to the OP's original question? If so, I'd appreciate an explanation.

no - retract inept.

bye.
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top