Hi,

I am using the OR operator in my while loop and its not very responsive:

while (transaction != 'Q' || transaction != 'q' ){}

The user previously entered a character for the variable transaction, however when the user enters 'Q' or 'q', the while loop is not skipped. Can anyone give me some insight?

Thanks

the letter cannot be both Q and q, so one or the other conditions must be true, so their OR is always true.

use this

while((transaction != "Q") && (transaction != "q")){
   .
   .
   .
}

or this

while(true){
   .
   .
   if(transaction.equalsIgnoreCase("q")){
      return;
   }
}

they both do the same thing:
they exit the loop when transaction changes to Q or q

Cheers guys for the Help.

ZackZak, i implemented your first solution, works perfectly, thank you.

Jamescherrill, thanks for the input, i guess i need to pay more attention to my algorithm design instead of jumping into the coding process.

Thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.