1

I am having trouble getting this nested while loop to work. I am using a Javascript based program that reads from 2 table columns based on the Header of the table. I am able to read from the tables but the loop is not working. My goal is to find when the neutral size of a wire becomes larger than the phase size and print the wire size at which this occurs. The code is as follows.

 CSA = 130
 NeutCSA = 0
 i = 0
 j = 0

 while (NeutCSA < CSA){
      j = 0
      while (NeutCSA < CSA){
           NeutCSA = colWireSize[i] * colNumberWires[j]
           if (colNumberWires[j] < 18){
                 j = j + 1
           }
      }
      if (colWireSize[i] < 10){
           i = i + 1
      } 
 }
 result = colNumberWires[j]

The tables look like this

colWireSize 2 3 4 5 6 7 8 9 10

colNumberWires 6 7 8 9 10 11 12 13 14 15 16 17 18

The program will find the condition and end the loop but not in the order I need it to. I need it to start at the first row of WireSizes and then loop through and multiple that value by NumberWires. If this value is less then CSA, go to the next WireSize and repeat the process until NeutCSA > CSA.

Thanks Pat

1 Answer 1

2

Your outer loop does not loop as the inner loop will always advance NeutCSA to >= CSA.

Did you mean to set the exact same conditional for each loop?

Sign up to request clarification or add additional context in comments.

2 Comments

Yes I ment to do that. I thought that if I set the same condition, then no matter what loop was running, it would break out whenever the condition was met. So if the inner loop condition was not met then the it would break to the outerloop and increment i. If the condition was still not met, then j would be reset to 0 and go through the inner loop again.
If possible, re-factor (re-write) your code so you don't have the non-looping loop. I think the process will expose some more helpful things to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.