某些时候,在嵌套使用if语句时,所有if语句看起来都非常相似,因为它们都在对一个完全相同的表达式进行求值,惟一的区别是每个if语句都将表达式的结果与一个不同的值进行比较。例如:
\n
if (day == 0)
dayName = “Sunday”;
else if (day == 1)
dayName = “Monday”;
else if (day == 2)
dayName = “Tuesday”;
else if (day == 3)
…
else
dayName = “Unknown”;\n
dayName = “Sunday”;
else if (day == 1)
dayName = “Monday”;
else if (day == 2)
dayName = “Tuesday”;
else if (day == 3)
…
else
dayName = “Unknown”;\n