The if statement judges the evaluation (comparison) result such as a numerical value or a character string. If the evaluation result is "true", the processing in the if block is executed. If the evaluation result is "false", combine the else statements.
if(Conditional statement) {
//Conditional statement is true(true)Is executed here at
}
else {
//Conditional statement is false(false)Is executed here at
}
It is necessary to judge the condition in order to branch the process such as if statement. Judgment is called "evaluation".
The switch statement allows you to specify the code to execute if the specified variable takes a specific value. Variables are specified in switch, and conditional values are specified in case. You can specify the code to execute after the case value :. The code block runs until break.
switch(variable) {
case value 1:
case value 2:
//This is executed when the value is 1 or 2.
break;
case value 3:
//This is done when the value is 3
break;
default:
//Value 1, 2,This is done when neither of 3 is
break;
}
Recommended Posts