Re: Loop doesn't behave the way it's supposed to.

From: Joona I Palaste (palaste_at_cc.helsinki.fi)
Date: 01/03/04


Date: 3 Jan 2004 21:09:50 GMT

Stephan Aspridis <s.aspridis@t-online.de> scribbled the following:
> Hi folks,

> a happy new year. I have a little problem with a program I am writing at
> the moment. A loop doesn't behave the way I'd like to (namely, the
> "break" is ignored). This is the code in question:

> ----------------------------------
> star[s].planet[0].orbit_distance =
> pow(SOLDENSITY/EARTHDENSITY,1.0/3.0)*sqrt(star[s].mass)*get_random(50.0,150.0)/100.0;

> for (p=0;p<orbcount-1;p++){
> x = p+1;
> star[s].planet[x].orbit_distance =
> star[s].planet[p].orbit_distance*get_random(1250.0,2500.0)/1000.0;
> if (star[s].planet[p].orbit_distance>star[s].orbit_limit)
> break;

Probably stupid question, since I was too lazy to work out the
mathematical algorithm, but are you sure it isn't because you are
assigning to star[s].planet[x].orbit_distance, but comparing
star[s].planet[p].orbit_distance? Those are two different variables.

> }//end for

> star[s].number_of_orbits = p;
> ----------------------------------

-- 
/-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Stronger, no. More seductive, cunning, crunchier the Dark Side is."
   - Mika P. Nieminen


Relevant Pages

  • Re: Loop doesnt behave the way its supposed to.
    ... I have a little problem with a program I am writing at ... A loop doesn't behave the way I'd like to (namely, ... > I asked the same question in de.comp.lang.c and the folks there came up ...
    (comp.lang.c)
  • Re: Jef tore down my picture on Quitbuddies
    ... can behave like 17 kinds of an idiot and still be entirely welcome. ... there were plenty of folks who decided to repost his message. ... HOW TO GET YOUR PHOTO ON QUITBUDDIES: ... requirement beyond a desire to share, and the evidence of simple civility. ...
    (alt.support.stop-smoking)
  • Re: OT: HP P*sses off China
    ... and force isarel to behave. ... The loop has to stop, ... Israel stop irritating the hell out of palestinians. ... And there will be no peace until all parties stop taking pot shots ...
    (comp.os.vms)
  • Re: Why arent most vi.lib VIs reentrant?
    ... Ken Pietrzak wrote:Thanks folks for your ... We generally use multiprocessor computers for our ... vi.lib would be reentrant by default. ... the array size or how many loop iterations I used, ...
    (comp.lang.labview)
  • Re: User Input Question
    ... point where the user will gain control? ... to loop to handle configuration for multiple machines? ... need to ask your questions inside the loop. ... "The only stupid question is the one you don't ask." ...
    (comp.lang.tcl)