change condition in if statement

Oct 18, 2015 at 12:11am
1
2
3
4
5
6
7
bool x = false;

if(!x){
    x = true;
}else{
    printf("Hello!");
}


Shouldn't this program print "Hello!"?


This works fine,

1
2
3
4
5
6
7
8
bool x = false;

if(!x){
    x = true;
}
if(x){
    printf("Hello!");
}



Why does first code not working?
Last edited on Oct 18, 2015 at 12:11am
Oct 18, 2015 at 12:14am
closed account (Eybjz8AR)
because if it matches the condition in the first statement it will skip the else statement completely because x is false.
Oct 18, 2015 at 12:31am
So that means if first condition works, it skips all rest conditions?
Oct 18, 2015 at 12:53am
yeah
Topic archived. No new replies allowed.