简体   繁体   中英

Java while loop doesn't want stop

I'm learning Java programming and have a problem with this code. My issue is I can't stop the second while loop ( while (done ==1){ .. } )

If I do done = 2, the program resume...

int stopme3 = 1;
while (stopme3 == 1) {        
    /* Appel de la méthode Afficher les propriétaires */
    AfficherProprio();
    int choix_proprio = ChoisirProprio();

    /* Appel de la méthode Afficher les Comptes du Propriétaire */
    AfficherComptesProprietaire(choix_proprio);

    /* Choix du compte à modifier */
    System.out.println("N° de compte:");
    int choixCompte = lectureClavier.nextInt();
    /* Test si comptes existants du proprio */
    if (choixCompte == tab_compte[choix_proprio]._num_compte) {
        int done = 1;
        while (done == 1) {
            /* Création d'une ligne comptable */
            tab_compte[choix_proprio].CreerLigneC();
            System.out.println("Ajouter une ligne comptable supplémentaire ?");
            System.out.println("1 - Oui");
            System.out.println("2 - Non");
            done = lectureClavier.nextInt();
        }
    } else {
        System.out.println("Compte sélectionné inexistant.");
    }
}

Help is much appreciated, thanks a lot.

int stopme3 = 1;
            while (stopme3 == 1) { // This loop will keep running till condition is true


int done = 1;
    while (done == 1) {// This loop will keep running till condition is true

Hence this will run infinitely. Hence you might want to do this way

  int stopme3 = 1;
  while (stopme3 == 1) { 

   if(some condition is met){
           stopme3  =2;
       }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM