Forloop not working?
ive been trying to make a script that procedurally generates roads, but ive been debugging the first bit of it and noticed something odd.
My Code:
public List<GameObject> straightRoads = new List<GameObject>();
void Start()
{
var otherScript = GetComponent<overworldFormation>();
roadGenerator(); //adds two different items to straitRoads
for (var corona = 0; corona < 7; corona++)
{
Debug.Log(corona);
Debug.Log(cycleTimes + 1);
for(var pneumonia = 0; pneumonia < straightRoads.Count + 1; pneumonia++)
{
Debug.Log(pneumonia);
Debug.Log(straightRoads.Count);
var remainder = pneumonia % 2;
if(remainder < 1)
{
var currentThing = straightRoads[pneumonia];
}
}
}
}`
(btw the variables corona and pneumonia are placeholder values) The problem is that corona should print 7 times, as the forloop states it should be doing, but when i run the code, it only prints once. The pneumonia value however, is printed twice (due to the list having 2 items in it)
Can someone help please
In case you didn't know, Unity's console will only print the same value once if you have the "Collapse" option ticked at the top of the console window (it will then show the count to the very right of the output). To ensure you're also seeing the same output as often as it prints, untick the Collapse option. Though that may not be the issue, as your corona value should be different each time.
Thanks for the information, but unfortunately that wasn't it; corona still is returned once
Your answer
![](https://koobas.hobune.stream/wayback/20220612222634im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
index number problems Forloop 1 Answer
For loop within Serializable class? 1 Answer
float in for loop isnt changing 1 Answer
How to count integer number inside a forloop in update function? 0 Answers
For Loop does two loops at once! 0 Answers