Find th efor loop error (simple!... I assume...)

This is a discussion on Find th efor loop error (simple!... I assume...) within the C++ Programming forums, part of the General Programming Boards category; Noobie query, I'm sure... Can someone spot the parse errors in the following code. It sems to lie in my ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    3

    Find th efor loop error (simple!... I assume...)

    Noobie query, I'm sure...

    Can someone spot the parse errors in the following code. It sems to lie in my one for loop. I wasn't sure how to put multiple statements in a single for loop.

    Code:
    for(i=1; i<=nruns; i++)
            {
            for(j=1; j<=nsims; j++)
                    {
                    if(T_mle[i][j] =0.0)
                            {
                            for(k=1; k<=nsims; k!=j; T_mle[i][k]!=0.0; k++)
                                    {
                                    T_mle[i][j]+=T_mle[i][k];
                                    }
                            T_mle[i][j]=T_mle[i][j]/(nsims-p);
                            }   
                    }
            }
    So I want the for loop to run for k=1 to nsims, skipping the cases where T_mle[i]k[]=0.0 as well as when k=j.

    Thanks guys.
    Last edited by Schmag; 06-22-2007 at 03:36 PM. Reason: Clarify

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    >> for(k=1; k<=nsims; k!=j; T_mle[i][k]!=0.0; k++)
    What are you trying to do there?

    >> skipping the cases where T_mle[i]k[]=0.0 as well as when k=j
    If you are trying to skip certain cases, you should skip them inside the body of the loop. The stataments in the for loop are only for initialization, termination and increment.

    >> if(T_mle[i][j] =0.0)
    Don't forget the difference between assignment and equality.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    102

    Exclamation

    Hmm the for loop syntax is as followed
    for(int x = 0; x <= 100; ++x)
    for(Variable ; Repeat While; Increment Variable)

    And that's your standard For loop

    Yours should be:

    Code:
    for(i=1; i<=nruns; i++)
            {
            for(j=1; j<=nsims; j++)
                    {
                    if(T_mle[i][j] == 0.0)
                            {
                            for(k=1; k<=nsims && k!=j && T_mle[i][k]!=0.0; k++) 
                                                                                           //If that's what you wanted.
                                    {
                                    T_mle[i][j]+=T_mle[i][k];
                                    }
                            T_mle[i][j]=T_mle[i][j]/(nsims-p);
                            }   
                    }
            }
    However it is always wiser to keep the for loop statement simple, so it would be better if you skipped or exited the for loop in the body as Daved stated.
    I'll let you do that part though.
    Last edited by JJFMJR; 06-22-2007 at 04:29 PM.
    My Favorite Programming Line:
    Code:
    #define true ((rand() % 2) ? true : false)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. could not find -lwsock32.lib
    By thomas_joyee in forum C++ Programming
    Replies: 8
    Last Post: 07-14-2008, 12:28 PM
  2. How to find O of threads ?
    By jabka in forum C Programming
    Replies: 3
    Last Post: 03-11-2008, 12:25 PM
  3. ld.exe: cannot find -l-lstdc++
    By Tonto in forum Tech Board
    Replies: 3
    Last Post: 04-10-2007, 11:20 PM
  4. Variable question I can't find answer to
    By joelmon in forum C++ Programming
    Replies: 3
    Last Post: 02-12-2002, 03:11 AM
  5. RE: Find out running processes from command prompt
    By sampatel in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-18-2001, 07:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21