Looping question

E

Eigenvector

Probably a dumb question, but I'm having problems with a while loop that I
would like to have execute in some code I'm writing.

Now what I'll post below is made up trivial code because what I'm ultimately
trying to do is mostly OT and far too complicated.

#define <stdio.h>

int mysterybox(int);

int main()
{
int a, b, c;

a=mysterybox(b);

while (a !=0 )
{
a=mysterybox(c);
}
}

The only problem that my code is faced with, outside of the atrocious
example is that unfortunately "a" sometimes equals 0 prior to entrance into
the while loop. Regardless of what "a" equals I need it to enter the while
loop.

Now it doesn't have to be a while loop, that's one of the reasons why I
suspect my question is trivial. It does however have to be a while
loop-like structure meaning it shouldn't terminate unless "a" does equal 0.
 
E

EventHelix.com

Probably a dumb question, but I'm having problems with a while loop that I
would like to have execute in some code I'm writing.

Now what I'll post below is made up trivial code because what I'm ultimately
trying to do is mostly OT and far too complicated.

#define <stdio.h>

int mysterybox(int);

int main()
{
int a, b, c;

a=mysterybox(b);

while (a !=0 )
{
a=mysterybox(c);
}
}

The only problem that my code is faced with, outside of the atrocious
example is that unfortunately "a" sometimes equals 0 prior to entrance into
the while loop. Regardless of what "a" equals I need it to enter the while
loop.

Now it doesn't have to be a while loop, that's one of the reasons why I
suspect my question is trivial. It does however have to be a while
loop-like structure meaning it shouldn't terminate unless "a" does equal 0.

Did you try the do-while loop? It will let you run once and the check
is at the end of the loop body.
 
P

pete

Eigenvector wrote:
#define <stdio.h>

int mysterybox(int);

int main()
{
int a, b, c;

a=mysterybox(b);

while (a !=0 )
{
a=mysterybox(c);
}
}

The only problem that my code is faced with, outside of the atrocious
example is that unfortunately "a" sometimes equals
0 prior to entrance into
the while loop.
Regardless of what "a" equals I need it to enter the while
loop.

Now it doesn't have to be a while loop,
that's one of the reasons why I
suspect my question is trivial. It does however have to be a while
loop-like structure meaning it shouldn't terminate
unless "a" does equal 0.


a = mysterybox(b);
do {
a=mysterybox(c);
} while (a !=0 );
 
B

Barry Schwarz

Probably a dumb question, but I'm having problems with a while loop that I
would like to have execute in some code I'm writing.

Now what I'll post below is made up trivial code because what I'm ultimately
trying to do is mostly OT and far too complicated.

#define <stdio.h>

int mysterybox(int);

int main()
{
int a, b, c;

a=mysterybox(b);

while (a !=0 )
{
a=mysterybox(c);
}
}

The only problem that my code is faced with, outside of the atrocious
example is that unfortunately "a" sometimes equals 0 prior to entrance into
the while loop. Regardless of what "a" equals I need it to enter the while
loop.

Now it doesn't have to be a while loop, that's one of the reasons why I
suspect my question is trivial. It does however have to be a while
loop-like structure meaning it shouldn't terminate unless "a" does equal 0.

Try do {...}while (a != 0);


Remove del for email
 
E

Eric Sosman

Eigenvector said:
Probably a dumb question, but I'm having problems with a while loop that I
would like to have execute in some code I'm writing.

Now what I'll post below is made up trivial code because what I'm ultimately
trying to do is mostly OT and far too complicated.

#define <stdio.h>

int mysterybox(int);

int main()
{
int a, b, c;

a=mysterybox(b);

while (a !=0 )
{
a=mysterybox(c);
}
}

The only problem that my code is faced with, outside of the atrocious
example is that unfortunately "a" sometimes equals 0 prior to entrance into
the while loop. Regardless of what "a" equals I need it to enter the while
loop.

Now it doesn't have to be a while loop, that's one of the reasons why I
suspect my question is trivial. It does however have to be a while
loop-like structure meaning it shouldn't terminate unless "a" does equal 0.

(void)mysterybox(b); /* assignment to `a' pointless */
do {
a = mysterybox(c);
} while (a != 0);
 
E

Eigenvector

EventHelix.com said:
Did you try the do-while loop? It will let you run once and the check
is at the end of the loop body.

--

Ah yes, I knew it was an easy answer - thanks all who replied.
 
C

CBFalconer

Eigenvector said:
.... snip ...

#define <stdio.h>

What is this? Useless, and erroneous.
int mysterybox(int);

int main()
{
int a, b, c;

a=mysterybox(b);
while (a !=0 )
{
a=mysterybox(c);
}
}

The only problem that my code is faced with, outside of the
atrocious example is that unfortunately "a" sometimes equals 0
prior to entrance into the while loop. Regardless of what "a"
equals I need it to enter the while loop.

int mysterybox(void);

int main(void) {
int a;

do {
/* nothing much */
} while (a = mysterybox());
return 0;
}
 
E

Eigenvector

CBFalconer said:
What is this? Useless, and erroneous.


int mysterybox(void);

int main(void) {
int a;

do {
/* nothing much */
} while (a = mysterybox());
return 0;
}

--


Whew! For a second I thought you were going to be a complete and utter
asshole after spotting a mistake in a totally contrived C program used only
for the purpose of example. I must have gotten off lucky for some reason,
maybe you were feeling more charitable than usual?

Next time I won't expect such kindness from a stranger.
 
N

Nick Keighley

Eigenvector said:
Whew! For a second I thought you were going to be a complete and utter
asshole after spotting a mistake in a totally contrived C program used only
for the purpose of example. I must have gotten off lucky for some reason,
maybe you were feeling more charitable than usual?

Next time I won't expect such kindness from a stranger.

comp.lang.c prefers it if you post real code. Describing regulars as
"assholes" tends to be counter productive if you are actually expecting
any help
rather than just trolling
 
E

Eigenvector

Nick Keighley said:
comp.lang.c prefers it if you post real code. Describing regulars as
"assholes" tends to be counter productive if you are actually expecting
any help
rather than just trolling

I'm sure Falconer can handle this himself, he doesn't need a bodyguard.
 
D

Debaser

I'm sure Falconer can handle this himself, he doesn't need a bodyguard.

I just posted a question myself after not visiting for years. I'd be
upset if the regulars weren't still described as "assholes". They're
the ones that know their stuff and all of you non-regulars can learn a
lot from them, as caustic as they are.

Remember, it's only text.
 
E

Eigenvector

Debaser said:
I just posted a question myself after not visiting for years. I'd be
upset if the regulars weren't still described as "assholes". They're
the ones that know their stuff and all of you non-regulars can learn a
lot from them, as caustic as they are.

Remember, it's only text.

No I'm afraid I don't agree. There is a big difference between the regulars
in this group and the regulars in other forums. The regulars in this forum
all have imperious tones. They act as if cutting remarks, harsh criticism,
and outright arrogant displays are somehow helpful or necessary tools of
teaching. While I appreciate that they must see the same basic question
over and over again I counter that nothing compels them to answer those
questions. Yet they do, typically with an unhealthy dose of condescention.

Perhaps its something intrinsic to computer programmers, years of never
having to interact with other adults at a high level has removed their
communcation skills. Or maybe the regulars in this group are regulars
because they don't actually go to offices and work with other people -
sitting at home and coding is all they do. I'm not apologizing for them,
nor making excuses.

What is that saying, the cure is sometimes worse than the disease. For some
of the regulars in this group I think that applies very accurately. Plonk
me all you want, it would spare me from having to endure your arrogance
again.
 
E

Eric Sosman

Eigenvector said:
[...] The regulars in this forum
all have imperious tones. [...]
> typically with an unhealthy dose of condescention.

We are not amused, and it's "condescension."
 
D

Default User

Eigenvector wrote:

No I'm afraid I don't agree. There is a big difference between the
regulars in this group and the regulars in other forums. The
regulars in this forum all have imperious tones.

*plonk*



Brian (tired of whiners)
 
L

Len Philpot

No I'm afraid I don't agree. There is a big difference between the regulars
in this group and the regulars in other forums. The regulars in this forum
all have imperious tones. They act as if cutting remarks, harsh criticism,
^^^
"all"? That's a bit sweeping, IMO. Even one counter example will
disprove such a claim (and there are many examples). I don't recall ever
seeing, e.g. Chris Torek employ cutting remarks, harsh criticisms, etc.
Or Morris Dovey, or Ben Pfaff, or ..., etc. Criticism, when given, is
usually well targeted, justified and ultimately educational, even if it
stings a bit at first.

I rarely have any interest in plugging into threads like this one
(regardless of newsgroup). I've mostly lurked here for a while and have
found "the regulars" to be very instructive, to say the least. Just the
same, with the minimal time I have to spend on code, I'd be a bit
hesitant to demonstrate just how much I've learned (or not)! :)
 

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,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top