Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6768273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:03:21+00:00 2026-05-26T15:03:21+00:00

I have an applet that allows the user to define values for 10 variables,

  • 0

I have an applet that allows the user to define values for 10 variables, all of which could be arrays. I then want the program to iterate over all possible combinations and then save the calculations to a variable.

Previously I hard-coded it to initialize the result array, SIGMA, by looping over every variable, regardless of if it is a vector or a single value, IE:

SIGMA = new Array(A.length);
for (i1=0; i1<A.length; i1++) {
  SIGMA[i1] = new Array(B.length);
  for (i2=0; i2<B.length; i2++) {
    SIGMA[i1][i2] = new Array(C.length);
    for (i3=0; i3<C.length; i3++) {
      ...
    }
  }
}

This results in a 10-dimensional SIGMA array, which makes processing really slow if a few or more variables are arrays.

What I’d like to do is to have it initialize SIGMA only for those variables that are an array and not a singular value. Therefore, if all variables are a single number except for two, say X and Y, then I’d want to have:

SIGMA = new Array(X.length);
for (i1=0; i1<X.length; i1++) {
  SIGMA[i1] = new Array(Y.length);
}

However, I’m not quite sure how the best way to do this would be, as the number of for loops would depend on the number of variables that are arrays. I’m thinking I either need to use a recursive function or somehow incorporate a while loop.

Anybody have any good ideas on how this can be done? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:03:21+00:00Added an answer on May 26, 2026 at 3:03 pm

    I was able to solve this problem by making a recursive function that included the for loops:

    sigma = new Array(eval(var_idx[0]).length);
    sigma_forloop('sigma', 0)
    
    function sigma_forloop(X, idx) {
        for (var i=0; i<eval(var_idx[idx]).length; i++) {
            eval(X + '[' + i + ']' + ' = new Array(eval(var_idx[idx+1]).length);')
            if (idx+2 < var_idx.length) {
                var Y = X + '[' + i + ']';
                sigma_forloop(Y, idx+1);
            }
        }
    }
    

    The variable ‘var_idx’ in an array of strings containing the variables that have more than one value, therefore, it’s those variables that I want to loop over.

    I’m sure there’s an easier way of doing it, but this works for now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a flash applet that I want to grab a remote XML file
I have an third-party applet that requires JRE v1.5_12 to work correctly. THe user
I have a list powered by jQuery UI's sortable that allows a user to
We have a web page (HTML javascript and PHP mostly) that allows a user
I have an applet that is communicating with a servlet. I am communicating with
I have an applet that throws this exception when trying to communicate with the
I have an applet that communicates with a servlet using Http (Not sockets). Currently,
I have a Java Applet that uses AWT. In some (rare) circumstances, the platform
I have a Java applet that is meant to run only on Windows. (It
I have an Java applet that loads native code through JNI. Everything worked just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.