next up previous
Next: Nested if's with mutually Up: Unit 05 Previous: Use of blocks in

Nested if's

We have a nested if when the then-branch or the else-branch of an if-else statement is again an if-else or an if statement.

Example: Given day, month, and year, compute day, month, and year of the next day.

int day, month, year, nextDay, nextMonth, nextYear;
...
if (month == 12) {
  if (day == 31) {
    nextDay = 1;
    nextMonth = 1;
    nextYear = year + 1;
  } else {
    nextDay = Day + 1;
    nextMonth = month;
    nextYear = year;
  }
} else {
  ...
}


next up previous
Next: Nested if's with mutually Up: Unit 05 Previous: Use of blocks in