- Home /
silly for loop problem
I feel like there is something obvious I am not seeing here but I have looked at it for hours. Can some one tell me why this is not doing the same thing as the commented code. The for loop works for x but it does not multiply step by a different c value each time. It just runs through as 1 every time...
for (int x = 118; x < 128; x++){
for(int c = 1; c < 11; c++){
g1.SetVert(x,i,step*c+sm1);
}
}
// g1.SetVert(118,i,step*1+sm1);
// g1.SetVert(119,i,step*2+sm1);
// g1.SetVert(120,i,step*3+sm1);
// g1.SetVert(121,i,step*4+sm1);
// g1.SetVert(122,i,step*5+sm1);
// g1.SetVert(123,i,step*6+sm1);
// g1.SetVert(124,i,step*7+sm1);
// g1.SetVert(125,i,step*8+sm1);
// g1.SetVert(126,i,step*9+sm1);
// g1.SetVert(127,i,step*10+sm1);
maybe in your code before the variable c is already declared...
Answer by richyrich · Nov 15, 2014 at 04:54 PM
You used a nested loop which was not required. Solution:
int c = 1;
for (int x = 118; x < 128; x++)
{
g1.SetVert(x, i, step * c + sm1);
//increments c as well each iteration
c++;
}
Oh wow duh.. thank you so much! Sometimes you just get stuck in the same method of thinking.
@ODIN$$anonymous$$ONG - No worries, sometimes its just a fresh pair of eyes. Please click on the accept button to remove it from the list of unanswered questions, so people know it has been solved.
Your answer
![](https://koobas.hobune.stream/wayback/20220613171602im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Use The Force Luke 1 Answer
What is the order of execution in a for loop? 1 Answer
Use for-i-loop var outside the loop 2 Answers
Logic Problems using for loops 0 Answers
Setting up an 2d grid in C# 3 Answers