Solved

For loop problems

Posted on 2004-04-25
2
192 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 96
Perl Awk Need Help 3 128
Whole sheet autoscrub still needed 19 51
x-bar in Google Sheets 2 70
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 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