Hi guys,
I set the 'for' statement to loop for 10 times but i'm not getting 10 loops. Sometimes it returns 6, at times it returns 4,3,7 etc. Only rarely did i get 10 return during runtime.
I've attached the screenshot of the output along.
Thanx in advance...
I set the 'for' statement to loop for 10 times but i'm not getting 10 loops. Sometimes it returns 6, at times it returns 4,3,7 etc. Only rarely did i get 10 return during runtime.
Code:
int y_axis = 200;
for (int q = 0; q < 10; q++) {
int rand = arc4random()%10;
if (rand == 0) {
NSString *msg = @"I've got 0";
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, y_axis, 320, 21)];
label.text = msg;
[scrollView addSubview:label];
[label release];
[msg release];
y_axis = y_axis + 20;
}
if (rand == 1) {
NSString *msg = @"I've got 1";
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, y_axis, 320, 21)];
label.text = msg;
[scrollView addSubview:label];
[label release];
[msg release];
y_axis = y_axis + 20;
}
if (rand == 2) {
NSString *msg = @"I've got 2";
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, y_axis, 320, 21)];
label.text = msg;
[scrollView addSubview:label];
[label release];
[msg release];
y_axis = y_axis + 20;
}
if (rand == 3) {
NSString *msg = @"I've got 3";
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, y_axis, 320, 21)];
label.text = msg;
[scrollView addSubview:label];
[label release];
[msg release];
y_axis = y_axis + 20;
}
if (rand == 4) {
NSString *msg = @"I've got 4";
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, y_axis, 320, 21)];
label.text = msg;
[scrollView addSubview:label];
[label release];
[msg release];
y_axis = y_axis + 20;
}
}
Thanx in advance...
Attachments
-
27 KB Views: 50