Link to home
Start Free TrialLog in
Avatar of LittlePerson
LittlePerson

asked on

For loop problems

Hi

I have a for loop performing pretty strangely

//MAX_CHANNELS = 1024

void CNewRunView::Accumulate(const double dblSpectra[], double dblAccum[])
{
      CString s;

      long l;

      for(l = MAX_CHANNELS; l > 0; l--);    //for(l = 0; l < MAX_CHANNELS; l++) also tried this for loop declaration
      {
            s.Format("\nAccum[%d] = %5.2f Spectra[%d] = %5.2f", l, dblAccum[l], l, dblSpectra[l]);
            TRACE(s);
            dblAccum[l] += dblSpectra[l];

            s.Format(" New Accum[%d] = %6.2f", l, dblAccum[l]);

            TRACE(s);
      }
}

When I debug the application if l = MAX_CHANNELS then l = 0 first time in the loop and it exits after one itteration.

if l = 0 then l = MAX_CHANNELS first time in the loop and then we exit.

Seriously confused on this one


Can anyone explain whats going on??


Thanks in advance
LittlePerson
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LittlePerson
LittlePerson

ASKER

Thanks

I really need to take a break!