- Home /
This question was
closed May 23, 2014 at 06:17 AM by
Fattie for the following reason:
Duplicate Question
(C#) For loop variable value not changing
I have this:
for (int a = -1; a <= 1; a++) {
for (int b = -1; b <= 1; b++) {
a and b don't change. I put a debug.log after that and it only says -1 for both a and b every time, although the loops does stop.
Comment
If you look at your console window, do you have the "Collapse" option enabled? That will sometimes combine multiple log messages into one message, which can be unintuitive if you're not expecting that.
Something beyond the code you posted is going on. Put the following on an empty game object and run:
using UnityEngine;
using System.Collections;
public class Example : $$anonymous$$onoBehaviour {
void Start() {
for (int a = -1; a <= 1; a++) {
for (int b = -1; b <= 1; b++) {
Debug.Log (a+", "+b);
}
}
}
}
Follow this Question
Related Questions
C# adding ints 1 Answer
Adding two variables from two different scripts. 4 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
foreach (or for-next loop) not updating local values 1 Answer