For example:
import java.util.Scanner;
public class PruebaDeMetodos {
static Scanner teclado ;
public static void main(String[] args) {
System.out.println("Escoje las opciones 'a' 'b' 'c':");
boolean anulado=false;
int precio = 5;
do{
teclado = new Scanner(System.in);
String accion = teclado.nextLine();
char opcion = accion.charAt(0);
switch (opcion){
case 'a':
precio = 5;
break;
case 'b':
precio = 0;
break;
case 'c':
anulado=true;
System.out.println("acabo el programa");
break;
default:
System.out.println("Escoje otra opcion");
break;
}
}while(!anulado || precio != 0);
if (anulado) {
System.out.println("Acumulado es true");
}else{
System.out.println("Acumulado es false");
}
}
}
The problem is that if I give option 'b' of the switch in console does not leave the cycle (should leave because it is equal to 0) I return to the cycle and return to enter the switch again choose 'b' and it does not come out until it chooses the option 'c' is when it leaves the cycle while or on the contrary I give 'c' (which should come out to be different from the value of voided) and it does not come out until the cycle repeats and I choose the option 'b'.
I wish I could help solve my doubt why not the first one breaks the cycle of while and I necessarily need to go through another switch option that breaks this loop.