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: 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)
  • Re: Simple loop question
    ... Hope this is not too simple or a stupid question: ... I have a slight problem with a loop. ... It is a simple numbers guessing game. ...
    (perl.beginners)
  • Re: "invisible" wireless headphone alternatives
    ... Have you tried the induction loop around the room instead of on the ... I know some folks will get a power amp and ... maybe you can chat with these folks about ways to make it better audio ...
    (rec.arts.movies.production.sound)