Solved

For loop problems

Posted on 2004-04-25
2
189 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:LittlePerson
2 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 50 total points
ID: 10911691
for(l = MAX_CHANNELS; l > 0; l--);

Remove ; in the end
0
 

Author Comment

by:LittlePerson
ID: 10911729
Thanks

I really need to take a break!

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 47
ADO Memory leak with DELPHI 2007 37 157
bobThere java chalenge 45 85
if loop in java 3 114
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now