Top
Previous Next
The Java Language CS 161 - Java

Control Flow - Branching

"if" statements

Execute some statements when a condition is satisfied (or not)
  if (expression that evaluates to a boolean result) {
     // The enclosed statements are performed if true
  ...
  }

  if (expression that evaluates to a boolean result) {
     // The enclosed statements are performed if true
    ...
  }
  else {
     // The enclosed statements are performed if true
    ...
  }

"switch" statements

Select one of a group (or several groups) of statements to execute
  switch (expression that results in an integer value) {
  case one_possible_value:
    ...
    break;
  case another_possible_value:
    ...
    break;
  ...
  default:
    ...
    break;
  }

Question: Why do I say "(or several groups)"


Top
Previous Next
jwd