2

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.

6
  • 2
    Ah, nice French code, very readable for everyone on the internet. He does change done, at done = lectureClavier.nextInt(); lectureClavier appears to mean keyboard. Commented Nov 1, 2013 at 10:06
  • 1
    What is the data which comes from lectureClavier.nextInt()? Commented Nov 1, 2013 at 10:07
  • The issue is not in done its in stopme3 which stays int, the outer loop keeps going. Commented Nov 1, 2013 at 10:08
  • Dystroy: I do not understand your question, sorry. Epsilon: lectureClavier.nextInt() ask to user if he want to continue or stop the boucle. (1 to continue, any other to stop) Commented Nov 1, 2013 at 10:14
  • Philipp: Yes, lectureClavier means keyboard ;) Commented Nov 1, 2013 at 10:22

1 Answer 1

3
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;
       }

}
Sign up to request clarification or add additional context in comments.

2 Comments

He was talking about the inner loop (while (done ==1){ .. }) not being finite. Your suggestion is about the outer loop.
Thanks you very much, it works now. :) I have added : if (done != 1) { done = 2; stopme3 = 2; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.