Conditionals

If ... else

if (expr) {
statements;
}
else if (expr) {
statements;
}
else {
statements;
}

Switch statement

switch (expr) {
case VALUE:
statements;
break;
case VALUE:
statements;
break;
default:
statements;
break;
}
  • The expr value must be a byte, short, int, or char.
  • Each case value must be a unique literal value; variables cannot be used.
  • Add a break statement to the end of the last case as a precautionary measure, in case additional cases are added later.
  • Braces are required.