I’m an experienced programmer so this cryptic behaviour is a total mystery to me.
I have a simple if-statement that should only be entered when exactly two boolean variables are false. However, the if-statement is for some reason entered when only one of them is false.
My code looks like this:
BOOL connected = [self connected];
NSLog(@"Connected to the internet: %@", connected ? @"YES" : @"NO");
BOOL notConnectedMessageShown = ((FOLDAppDelegate *)[[UIApplication sharedApplication] delegate]).notConnectedMessageShown;
NSLog(@"notConnectedMessageShown: %@", notConnectedMessageShown ? @"YES" : @"NO");
if (!connected && !notConnectedMessageShown);
{
NSLog(@"Entering if statement");
}
And the NSLogprints the following:
"Connected to the internet: YES"
"notConnectedMessageShown: NO"
"Entering if statement"
I really do not understand. Since the first variable is truein the first place, the entire if-statement should be skipped according to my programming skills?
Does anyone have an idea of what is going on here?
You have a semicolon at the end of your
ifThis way the block for a “true” condition is simply empty, and your code always enters the block right after it.
It should be this: