Reputation: 15
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
Upvotes: 1
Views: 3604
Reputation:
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?
Upvotes: 2