user12372692
user12372692

Reputation:

Expected expression before else statement

I get an error saying Expected expression before my else-statement but I do not know why. I searched through other posts but I cant find a solution.

- (void)setDeviationSize:(double)newDeviation
{
        if (newDeviation != 0) {
            deviationLayer.lineWidth = 2.0 / newDeviation;
            if (newDeviation * pixelPerMeter * scrollView.zoomScale < 2 * cPointRadius) {
                deviationLayer.hidden = YES;
            } else {
                deviationLayer.hidden = NO;
                deviationLayer.transform = CATransform3DMakeScale(newDeviation, newDeviation, 0);
            }
        } else {
            deviationLayer.hidden = YES;


        } else  <---- EXPECTED EXPRESSION {

            for(LectureModel* lecture in lectures) {
            NSString *title;
            if([lecture.title length] > 30) {
                title = [NSString stringWithFormat:@"%@...", [lecture.title substringToIndex:30]];
            } else {
                title = lecture.title;
            }

            [alert addActionWithTitle:title handler:^(UIAlertAction * _Nonnull action) {
                LectureModel* full = [LectureModel findById:lecture.id];
                if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
                    [self showModelInPopover:full];
                } else {
                    [[TransitionManager shared] openModelInCatalog:full];
                }
        }
        [self presentViewController:alert animated:YES completion:nil];
             }
             }
}

What am I missing?

Upvotes: 0

Views: 76

Answers (2)

Arnab_Datta
Arnab_Datta

Reputation: 672

@user12372692

In order to achieve what you want, there are two ways to solve this -

A. if else condition making.
B. using switch case.

Way A :-

if else condition is written like following :-

if (condition 1) {
    /* do something for condition 1 is true */
} else if (condition 2) {
     /* do something for condition 2 is true */
} else   { 
   /* do something for  both condition 1 and 2 are false. */
}

so as per this your condition should be :-

if (newDeviation != 0) {
    /* do something  */
} else if (OtherCondition) {
     /* do something*/
} else   { 
   /* do something for  both above two conditions are false */
}

Way B :-

switch(newDeviation){
   case (newDeviation != 0 ) : {/* Do your work */}; break;
   case (condition 2) : {/* Do your work */}; break;
   case (condition 3) : {/* Do your work */}; break;
}

Upvotes: 0

Elvereth
Elvereth

Reputation: 95

Like vadian and luk2302 pointed out you have an if statement with two else attached to it, so the compiler doesn't understand what the second else is related to and throwing the error.

Maybe you wanted something like

if (newDeviation != 0) {
    /* do something */
} else if (someCondition) {
    /* do something different */
} else   { 
   /* do something else */
}

If this is not the logic you want, please explain what you want to achieve, so we can help you better.

Upvotes: 1

Related Questions