Consider the following two if sequences:
if (x < y)
if (x < z)
min = x;
else
min = z;
else
if (y < z)
min = y;
else
min = z;
if (choice == 1)
handleDeposit();
else if (choice == 2)
handleWithdrawal();
else if (choice == 3)
handleBalanceInquiry();
- in the first sequence, the conditions being tested are semantically unrelated, and deal with
difference pairs of variables/values.
- The indentation reflects this, the
x < z
condition is indented because it is subsidiary to
the x < z
condition
- If the second sequence, the conditions are all semantically related, in each case,
choice
is being compared
against a value
- This is the typical scenario that calls out for a
switch