vendredi 26 mai 2017

How to change boolean of if condition inside the condition in C

To simplify what i am trying to do, look at this example:

bool test = false;
while(whatever){
    if (test == false){
        printf("1234");
        test = true;
    }

    if(skyIsBlue == true){
        //do something and maybe set test = false;
    }
}

In other programming languages, i'd expect the Program to print "1234" at least once, C obviously doesn't. I found this (Run if statement in loop only once) and other simmilar workarounds, but thoose would only work if i wouldn't plan to set "test = true" later on.

Could someone point out where my mistake is? Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire