- Home /
More than one row in an array not displaying in a FOR loop
Hello everyone.
I've got 5 columns and over 1300 rows of data which I've managed to retrieve into an array called: resultArray. I'm using the following loop to try and display each row into a corresponding GUIText variable:
for (var value : String in resultArray)
{
hud.openPrice = resultArray[0];
hud.highPrice = resultArray[1];
hud.lowPrice = resultArray[2];
hud.closePrice = resultArray[3];
hud.volumeNum = resultArray[4];
yield WaitForSeconds (1);
}
I get the first row of data to display perfectly, however, every subsequent row doesn't display. What am I not doing?
I edited "solved" out of the title...that's not necessary here; please accept the answer ins$$anonymous$$d.
Answer by Eric5h5 · May 24, 2010 at 07:09 PM
Your loop is just doing the same exact thing over and over again, by assigning the first five entries in "resultArray" to the "hud.*" variables. Presumably you want to do something with the "value" variable, which is currently going unused.
the value variable was there for printing to the console. that line of code isn't in the loop(...print(value)...). When I do include it, however, it prints all the values within the array one after the other. How would you get row after row of data then? Should I put the code in in a different loop?
@redrocket: $$anonymous$$aybe something like for (i = 0; i < resultArray.Length; i += 5) { hud.openPrice = resultArray[i]; hud.highPrice = resultArray[i+1]; etc.
Answer by redrocket · May 24, 2010 at 08:28 PM
Eric,
Thanks for the insight, here's the working code:
for (i = 0; i < resultArray.length; i += 5)
{
hud.openPrice = resultArray[i];
hud.highPrice = resultArray[i+1];
hud.lowPrice = resultArray[i+2];
hud.closePrice = resultArray[i+3];
hud.volumeNum = resultArray[i+4];
yield WaitForSeconds (1);
}
I'm glad it works, but ins$$anonymous$$d of writing "[SOLVED]", you're supposed to accept the best answer. That's how questions are marked solved.
Your answer
Follow this Question
Related Questions
JS Loop question 2 Answers
the for statement in unity 3d for iphone 1 Answer
Need help cycling through an array with a 'for' loop. 0 Answers
My RPC gets called, but doesn't do the math before it 1 Answer