Reputation: 171
I have two for loops that add subviews to the view. The first one adds all the subviews, but the second for loop is not even executed! Whats Up?
- (void)createBoxes
{
for (int i; i<5; i++) {
GameBox *box = [[GameBox alloc] initWithFrame:CGRectMake((i * 64) + 7, 50, 50, 50)];
[self.view addSubview:box];
}
for (int e; e<5; e++) {
GameBox *box1 = [[GameBox alloc] initWithFrame:CGRectMake((e * 64) + 7, 107, 50, 50)];
[self.view addSubview:box1];
}
}
Upvotes: 1
Views: 84
Reputation: 2468
Proper way would be to initialize variables :
int i = 0;
int e = 0;
Otherwise you never know which value you'll get.
Upvotes: 8
Reputation: 5825
Why are you not initialising your loop variables? These are not standard for loops at all.
Upvotes: 3