命令 Instruction Type
Format
swicth(調べる) swicth (check value)
{ (
case 1:1だった場合の処理; break; case value 1: If the value of a process; break;
case 2:2だった場合の処理; break; case value 2: The values of the two cases were handled; break;
case 3:3だった場合の処理; break; value case 3: if the value of treatment was 3; break;
:
default:caseで指定した以外の場合の処理; default: case processing in the case of non-specified value;
} )
Commentary
switchで調べる、変数がcaseで一致した場合に処理を行います。 switch value in the study, the variables in the case when matching process. いずれのcaseとも違う場合にはdefaultで指定した処理が行われます。 If either case is different from the default value will be specified in the process.
サンプルコード Sample code
n = (new Date()).getSeconds(); n = (new Date ()). getSeconds ();
n = n % 3; n = n% 3;
switch(n) switch (n)
{ (
case 0:outputs[0] = "ゼロです"; break; case 0: outputs [0] = "is zero"; break;
case 1:outputs[0] = "壱です"; break; case 1: outputs [0] = "is壱"; break;
default:outputs[0] = "0と1以外です"; default: outputs [0] = "0 and 1 are non-";
} )