iteration over several variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Saeid SSS
    New Member
    • Dec 2011
    • 2

    iteration over several variables

    Hello. I want to execute some instructions while iterating over all possible values for several variables. if the number of variables are few, I can write for loops inside eachother for this purpose. But here I have like 100 variables in a vector. and i might also change this number for another run. so that's not a practical solution... I wonder if there is an innovative way to do that?
    Assume I'd like to compute sum(R1*R2*...*R n) for all Ri between 0 and r. Please don't simplify the equation, as that's not the real thing that I want to compute :-)
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    I would suggest you write a function that given 1 set of variables returns the next set (or an end flag).

    Then you can use the pseudo code

    Code:
    vector<> VariableSet;
    
    DO
       // Perform operation on VariableSet
    
       HaltFlag = GetNextSet(VariableSet);
    
    UNTIL HaltFlag == TRUE

    Comment

    • Saeid SSS
      New Member
      • Dec 2011
      • 2

      #3
      Thank you!!!!!!!!!!!! !!!!!!!

      Comment

      Working...