Casio FX-890P Owner's Manual page 116

Casio personal computer owner's manual
Table of Contents

Advertisement

switch() case default
PURPOSE: executes various statements depending on the value of the parameter.
FORMAT: switch (expression) { [case constant i: statement i ]; default: statement; };
PARAMETERS:
1. expression must be an integer type (char, int, long, signed or unsigned).
2. constant i (there is no limit to the number of "case: constant i" statements) is a
constant from the same type as expression.
EXPLANATION:
1. expression is evaluated, and compared to each constant.
2. If a constant matches the value of expression, the statements following the
corresponding case are executed, until a "break" statement is found.
3. If no constant matches the value of expression, the statements following
"default" are executed.
4. Note: In absence of a "break", the execution of statements carries on. See the
second sample program.
SAMPLE PROGRAM:
/* Switch break example */
/* #include <stdio.h> */
main(){
int a;
printf("¥nEnter a value:");
scanf("%d",&a);
switch(a){
case 1:
printf("¥nThis is case 1");
break;
case 2:
printf("¥nThis is case 2");
break;
case 3:
printf("¥nThis is case 3");
break;
default:printf("¥nDefault case");
}
}
/* Switch w/o break example */
/* #include <stdio.h> */
main(){
int a;
printf("¥nHow Many Players:");
scanf("%d",&a);
switch(a){
case 4: Rst_Score(4);
case 3: Rst_Score(3);
case 2: Rst_Score(2);
case 1: Rst_Score(1); break;
default: printf("¥nNot possible");
}
}
SEE: if() else, break
116

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Z-1grZ-1

Table of Contents