case 3,5,9:

Messages in english

Modérateur : xcasadmin

compsystems
Messages : 561
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

case 3,5,9:

Message par compsystems » jeu. sept. 13, 2018 4:49 pm

Hello, is possible that CASE operates with several options?
case 3,5,9:

Code : Tout sélectionner

test_switch():={

	local c; 
	assume(c,DOM_INT);

	DispG; ClrIO; ClrGraph; 

	input("c",c);  

	switch(c){
		case 1:{
			printf("1");
			break;
		}
		case 3:{
			printf("3, 5 o 9");
			break;
		}
		case 7:{
			printf("7");
			break;
		}
		default:{
			printf("not is 1, 3, 5, 7, 9");
			break;
		}
	}

	Pause; DispHome; 
	return Done;
}:;

parisse
Messages : 5739
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: case 3,5,9:

Message par parisse » ven. sept. 14, 2018 9:10 am

No...

compsystems
Messages : 561
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Re: case 3,5,9:

Message par compsystems » ven. sept. 14, 2018 1:29 pm

the following code why does not it work?

case 3:{nop}
case 5:{nop}
case 9:{...

Code : Tout sélectionner

sin_titulo_05():={

	local c; // definir la varible de consulta
	assume(c,integer);

	DispG; ClrIO; ClrGraph; // inicia la consola entrada/salida, luego limpiar pantalla

	input("c",c);  


	switch(c){
		case 1:{
			printf("1");
			break;
		}
		case 3:{nop}
                case 5:{nop}
		case 9:{
			printf("3, 5 o 9");
			break;
		}


		case 7:{
			printf("7");
			break;
		}
		default:{
			printf("no es 1, 3, 5, 7, 9");
			break;
		}
	}

	//Pause; DispHome; // cierra la consola entrada/salida
	return Done;
}:;

parisse
Messages : 5739
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: case 3,5,9:

Message par parisse » ven. sept. 14, 2018 3:05 pm

Xcas case does not follow exactly the same rule as in C, if there is no break in a case then the next case are not taken but the default case is executed. In other words, put a break unless you know exactly what you do.

Répondre