samedi 18 mars 2017

Java : why is my if statement not affecting the loop condition? [duplicate]

This question already has an answer here:

Im not sure why but my if statement isnt changing the value of the boolean which is the condition to exit the loop. Can someone please help me figure out what i did wrong?

from my understanding, when i input "Yes" sec0 isnt set to true.

boolean sec0 = false;
do{ 
    System.out.println("Choose_Ride+"+ " is your desired ride? Yes/No");

    String setChoice = In1.nextLine();

    if (setChoice == "Yes"){
        sec0 = true;
        break;
    }
    else if(setChoice == "No") {
        sec0 = false;
        break;
    }
}while(sec0 == false);

Aucun commentaire:

Enregistrer un commentaire