Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

For loop problems

Posted on 2004-04-25
2
Medium Priority
?
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 200 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

704 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