Top
Previous Next
Java Arrays, Objects, Methods CS 161 - Java

Last Week - Control Flow - Branching

"if" statements

  if (expression that evaluates to a boolean result) {
     // Perform the enclosed statements if true
    ...
  }
  else {
     // Perform the enclosed statements if not true
    ...
  }

"switch" statements

  switch (expression that results in an integer value) {
  case 42:  // or whatever a possible value of expression is
    ...
    break;
  case 39:  // or whatever another possible value is
    ...
    break;
  ...
  default:  // (optional) catch all other values
    ...
    break;
  }

Top
Previous Next
jwd