fi12
fi12

Reputation: 485

Code will never be executed warning

In my previous question, I asked why my application was terminating early. It turns out I'm getting this warning on one of the lines below and that may help me solve my problem.

Here's the code:

NSMutableArray *redValues = [NSMutableArray array];
NSUInteger redValuesLength = [redValues count];
float totalOne, diffForAverage;
int amount = 1;
__block int counter = 0;
NSInteger j;

GPUImageVideoCamera *videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

GPUImageAverageColor *averageColor = [[GPUImageAverageColor alloc] init];
[averageColor setColorAverageProcessingFinishedBlock:^(CGFloat redComponent, CGFloat greenComponent, CGFloat blueComponent, CGFloat alphaComponent, CMTime frameTime)
 { 
     NSLog(@"%f", redComponent);
     [redValues addObject:@(redComponent * 255)];
 }];

[videoCamera addTarget:averageColor];
[videoCamera startCameraCapture];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 27 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
    [videoCamera stopCameraCapture];
});

totalOne = [redValues[25] floatValue];
float average = totalOne / amount;

for (j = (counter + 25); j < (redValuesLength - 25); j++)
{
    diffForAverage = average - [redValues[j + 1] floatValue];

    if (diffForAverage > -1 && diffForAverage < 1)
    {
        totalOne += [redValues[j + 1] floatValue];
        amount++;
        [arrayOne addObject:[NSNumber numberWithInt:(j - 25)]];
        counter++;
    }

    else
    {
        if (arrayOneLength >= 15)
        {
            break;
            counter++; // WARNING OCCURS HERE
        }

        else
        {
            [arrayOne removeAllObjects];
            totalOne = [redValues[j + 1] floatValue];
            counter++;
        }
    }
}

Why would the commented line above never be run? Is it a problem with my for loop, or my if statement, or something else entirely?

Upvotes: 0

Views: 1709

Answers (1)

silicon_valley
silicon_valley

Reputation: 2689

Because you have a break command just before it. The break command will immediately take you out of the for loop, so the next line won't be executed.

Upvotes: 4

Related Questions