- Home /
The question is answered
For Loop is completely skipped over. no idea why
Hi guys, I'm trying to run a forloop in the script, but unity completely skips over the code and I have no idea why. No compile errors and call loop debug message works, as well as a debug message after the BuildThis function is called also work, but the "in loop" message never appears. Also the holddiff has a value 2.
public void BuildThis(){
GetIndexedQuote();
UnityEngine.Debug.Log ("call loop");
for (var j=0; holddiff < j; j++) {
UnityEngine.Debug.Log ("in loop");
GenThat();
}
}
Thanks for your time.
And that is why. Look at your for logic. In specific:
What does J start as? What is holddiff? What has to be true for the body to run?
When making a for loop, say it in words.
For variable j, which is zero, While holddiff is LESS THAN j, increment j.
Did you mean to say,
j < holddiff
That's some really odd code. $$anonymous$$ight look into a better program$$anonymous$$g guide. Any (probably non-Unity) C# book should do a better job.
Answer by Jeff-Kesselman · Jun 26, 2014 at 12:15 AM
Look at your for logic. In specific:
What does J start as?
What is holddiff?
What has to be true for the body to run?
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
AddComponent Loop 1 Answer
Making a bubble level (not a game but work tool) 1 Answer
For Loop Array, skip 1 value 2 Answers